简体   繁体   English

$ _SESSION在zend中不起作用

[英]$_SESSION in zend not working

I am new to zend framework and I would like to use $_SESSION, but after I start the session using session_start and store a session variable, I am not able to access that variable on another page. 我是zend框架的新手,我想使用$ _SESSION,但是在使用session_start启动会话并存储会话变量之后,我无法在另一个页面上访问该变量。

I know that we can use Zend session namespace but for some reason I would like to stick to $_SESSION. 我知道我们可以使用Zend会话命名空间但出于某种原因我想坚持使用$ _SESSION。

in controller 1 ->
session_start();
$_SESSION['uid']=$this->_user_id;

in controller 2
session_start();
echo 'this is test comment for session '.$_SESSION['uid'];

Output in view of controller2 根据controller2输出
this is the test comment for session 这是会话的测试评论

you need to go to the config/autoload/global.php and add session configuration there if it is not: 你需要转到config / autoload / global.php并在那里添加会话配置,如果不是:

'session' => array(
    'config' => array(
        'class' => 'Zend\Session\Config\SessionConfig',
        'options' => array(
            'name' => 'myapp',
        ),
    ),
    'storage' => 'Zend\Session\Storage\SessionArrayStorage',
    'validators' => array(
        'Zend\Session\Validator\RemoteAddr',
        'Zend\Session\Validator\HttpUserAgent',
    ),
),

you don't need to use session_start() at all. 你根本不需要使用session_start() Then you can set or read sessions without any problem. 然后,您可以毫无问题地设置或读取会话。

Why do you want to access the Session directly? 为什么要直接访问Session? That's all handled by Zend Framework. 这一切都由Zend Framework处理。 Please use the Session Manager ( http://framework.zend.com/manual/current/en/modules/zend.session.manager.html ) instead. 请改用会话管理器( http://framework.zend.com/manual/current/en/modules/zend.session.manager.html )。 It provides an abstraction layer. 它提供了一个抽象层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM