Skip to content

How to Create,Get,Check Sessions in Zend Framework 2?

Last updated on December 21, 2022

In GF2 in order to use Sessions we should use this use ZendSessionContainer; class. This class Container extends of ArrayObject and instantiates with the ARRAY_AS_PROPS flag which means you can easily iterate through properties and read/write them.

After placing the above line of code in place, you need to instantiate the ZendSessionContainer class and pass a name to the constructor (the name is optional).

$session = new Container('user');

How to set value in session

$session->offsetSet('username', 'arjun');

How to Read or Get Session Value By Key

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

How to Check for key exists in the session

$session->offsetExists('username');
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments