Accessibility of a session in a view

2019-08-19 05:59发布

问题:

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);
?>