视图中会话的可访问性 [英] Accessibility of a session in a view

查看:40
本文介绍了视图中会话的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中创建了一个 Zend 会话:

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');
}

我已经测试了 $sessionUser->data,它包含正确的数据.但是我需要在另一个视图中获取此会话,并且在那里,它不再起作用...

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...

例如

<?php var_dump($sessionUser->data->prenom); ?>

显示NULL"它在前一个视图中运行良好,但在此视图中不起作用.

displays "NULL" it worked fine in the previous view but not in this one.

我已经放置了我的 Zend_Session::start();在我的控制器的 init() 函数中...

I have placed my Zend_Session::start(); in the init() function of my controller...

预先感谢您的帮助

推荐答案

如果你想在另一个视图中使用你的会话,你必须再次实例化它.因此,如果您使用以下代码,您应该能够访问您的数据:

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

这篇关于视图中会话的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆