How to use Zend\Session in zf2?

后端 未结 7 2295
轻奢々
轻奢々 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:13

    Definitely yes, you should use Zend\Session\Container

    Container extends of ArrayObject and instantiates with ARRAY_AS_PROPS flag that means you can easily iterate through properties and read/write them, e.g.

    use Zend\Session\Container as SessionContainer;
    
    $this->session = new SessionContainer('post_supply');
    $this->session->ex = true;
    var_dump($this->session->ex);
    

    First argument is session namespace and second — Manager. Manager is a facade for Storage and SaveHandler and it's configured with ConfigInterface in order to save your session data in DB or Memcache server.

提交回复
热议问题