How to use Zend\Session in zf2?

2019-01-22 02:26发布

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 find any examples in the internet.

7条回答
小情绪 Triste *
2楼-- · 2019-01-22 02:57

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.

查看更多
登录 后发表回答