Skip to content

Storing Objects as Session Variables with Zend Framework

Zend Session handles the serialization and unserialization of the Objects you want to store.

Typically I only store service call objects in the session such as Shipping Rates. In order to utilize your Objects from the session, the Object (or class) must be defined prior to the session start call. If you do not define the Objects first, they will get defined as _PHP_Incomplete_Class and thus not work.

Your Boostrap.php (or Initializer depending on configuration) file should look something like this:

//Object I want to use as a session variable
class_exists('My_Class_Name', true);

This will do a check to see if that class exists on the file system, and ensure that it automatically get’s loaded. You should then be able to store the object in the session by doing something like this:

$session = new Zend_Session_Namespace('object');
if(is_null($session->obj)) {
        $session->obj = new My_Class_Name();

Posted in Zend Framework 1.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK


(required, but never shared)

or, reply to this post via trackback.