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.

No comments:

Post a Comment

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...