Thursday, 6 October 2016

How to get session in Zend Framework 2

In ZF2 instead of using Sessions we should use this use ZendSessionContainer class. The Container class extends of ArrayObject and instantiates with ARRAY_AS_PROPS flag so you can easily iterate through properties.Now you need to instantiate the ZendSessionContainer class and pass a name to the constructor.

Zend 2 Session

use Zend\Session\Container;
$sessionObj = new Container('user');

Set the session :

$sessionObj->offsetSet('name', 'wantcode');

Read or Get Session Value By Key in zf2:

$name = $sessionObj->offsetGet('name');

Check session key exist:


I hope you like this article please comment and share.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts