Using ZendSession – Rob Allen's DevNotes
This is a quick note on how to use ZendSession.
Although the component name is ZendSession, you actually interact with ZendSessionContainer to store and retrieve session data:
use ZendSessionContainer ;
$session = new Container ( 'SomeKeyName' ) ;
ZendSessionContainer's constructor takes a string argument which is the name for this container ('SomeKeyName' in this case). It's optional and if you don't set it, then it is set to 'Default'. The name allows you to use the same session keys in different containers.
To set data into the session:
$session -> pageNumber = 2 ;
and to retrieve it again:
$pageNumber = $session -> pageNumber ;
Behind the scenes, ZendSession has replaced _SESSION with an instance of ZendSessionStorageSessionStorage. Fortunately this object extends ArrayObject, so you can still access $_SESSION as if it was an array. Our particular piece of data is at $_SESSION['SomeKeyName']['pageNumber'] and is set it to 2.