In ProjectsController.php I’m setting a session variable as I’d like that info to be accessible in ALL controllers, models and views:
$this->Session->write('Project.title', $this->Project->title);
Now, when I try access it from Projects view, like this:
<p>Project: <strong>
<?php if (isset($session->read('Project.title'))):
$session->read('Project.title');
?>
<?php else: ?>
Not selected
<?php endif; ?>
</strong></p>
I’m getting the following error:
Fatal error: Can't use method return value in write context
Which refers to the second line of above code.
I’ve been through CakePHP documentation and also searched SO, what am I doing wrong here?
Thanks!
EDIT:
I’ve also tried using:
$this->Session->read('Project.title')
resulting in the same error message.
You should do what PHP tells you once in a while 🙂
The error message is pretty clear. You cannot use isset() and empty() this way.
They only work with variables direcly, not methods. So use
as documented in the cookbook
you could also do
or even
the last one is not cakephp coding convention, though.