How to use Zend\Session in zf2?

后端 未结 7 2206
轻奢々
轻奢々 2020-12-13 18:48

Does anybody try zf2? I can not understand new mechanism of using sessions in zf2. How can I write and read to/from the session in new zend framework?

Also I can not

相关标签:
7条回答
  • 2020-12-13 19:26

    Some examples of zf2 sessions usage:

    Session creation:

    use Zend\Session\Container;
    $session = new Container('base');
    

    Check that key exists in session:

    $session->offsetExists('email')
    

    Getting value from the session by key:

    $email = $session->offsetGet('email');
    

    Setting value in session:

    $session->offsetSet('email', $email);
    

    Unsetting value in session:

    $session->offsetUnset('email');
    

    And other easy way to use session are:

    $session = new Container('foo');
    

    // these are all equivalent means to the same end

    $session['bar'] = 'foobar';
    
    $session->bar = 'foobar';
    
    $session->offsetSet('bar', 'foobar'); 
    
    0 讨论(0)
提交回复
热议问题