问题
I have created a Zend session in a view:
$user = Tools::getUserByLoginAndPassword($form);
if ($user instanceof Membre)
{
$sessionUser = new Zend_Session_Namespace('user');
$sessionUser->data = $user;
$this->_redirect('/adresse');
}
I have tested $sessionUser->data, it contains the right data. But i need to get this session in another view, and there, it's not working anymore...
for instance
<?php var_dump($sessionUser->data->prenom); ?>
displays "NULL" it worked fine in the previous view but not in this one.
I have placed my Zend_Session::start();
in the init() function of my controller...
thanks in advance for your help
回答1:
If you want to use your session in another view, you have to instantiate it again. So if you use the following code you should be able to access your data:
<?php
$session = new Zend_Session_Namespace('user');
Zend_Debug::dump($session->data);
?>
来源:https://stackoverflow.com/questions/12562128/accessibility-of-a-session-in-a-view