Accessibility of a session in a view

邮差的信 提交于 2019-12-11 14:11:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!