-1

EDIT FOR THE ADMINS: IT IS NOT THE SAME QUESTION AS THE ONE ALREADY ASKED, SINCE THE ORIGIN OF THE ISSUE IS DIFFERENT!!!

I am trying to display the current language selected, which is saved in the sessions table. What I did first was the simple statement:

<?php echo $this->session->userdata("language"); ?>

which works quite well. The problem here is, that the language is saved into the session table in English and lower case, means: "english", "german", "spanish", etc

I then tried to resolve this using an if statement as follows:

<?php if ($this->session->userdata("language") = spanish) {  echo 'Español'; } else if ($this->session->userdata("language") = english) {  echo 'English'; } else echo 'Deutsch'; ?>

unfortunately, this returns:

Fatal error: Can't use method return value in write context in /home/.../.../.../app/views/header.php on line 270

Any hint on what I am doing wrong? Thanks for your quick help ;)

2
  • 1
    I think you meant to use == Commented Oct 24, 2013 at 18:03
  • 1
    @MikeB Thanks, but it is not the same issue. Here it was caused by the missing ==, which was not the case in your quoted question. Thanks anyways :) Commented Oct 24, 2013 at 18:11

4 Answers 4

2

You need to use a comparison operator == (I'm sure your = is just the usual common typo), since you can't assign a value (write) to the $this->session->userdata('anything') (method return), i.e.

Can't use method return value in write context

 <?php if ($this->session->userdata("language") == 'spanish') {  
          echo 'Español'; 
        } 
       elseif($this->session->userdata("language") == 'english') { 
          echo 'English'; 
      } 
      else echo 'Deutsch'; 
    ?>
Sign up to request clarification or add additional context in comments.

1 Comment

argh... its always the same when someone asks you to "quickly" code something lol Thanks so much, great help!!!
1

== operator and quoted strings should solve it:

<?php 
if ($this->session->userdata("language") == 'spanish') {  echo 'Español'; } 
else if ($this->session->userdata("language") == 'english') {  echo 'English'; } 
else echo 'Deutsch'; 
?>

Comments

0

Make use of a SWITCH Statement to achieve this [Code will really look readable]

<?php 

$language=$this->session->userdata("language");

switch($language)
{
    case "spanish":
        echo 'Español';
        break;

    case "english":
        echo 'English';
        break;

    //.... goes on



}

Comments

0

To compare two things you should be using the == Operator. Also string values should be wrapped into quotes "myStringValue".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.