Matt--thanks for your reply. So, I think I'm clear about the need to implement the __sleep() method in the object to perform serialization--return an array with the list of properties you want serialized.
I have a couple more questions on this: a) if I have properties in my class which are themselves objects (ie. a Zend_Db_Select object), can I just include the parameter name in my __sleep() method and will their class inherit/handle the serialization for my class? b) I'm noticing that when I assign a standard array type to the session namespace, it doesn't persist either. For example, let's say I want to retrieve and store the POST parameters in my session vars, ie: $sessionVars->searchParams = $front->getRequest->getPost(); This seems strange since PHP's session handler has always handled arrays in my experience. Is there something additional I need to do to handle the standard array type with a Zend Session namespace? Matthew Ratzloff wrote: > > Of course; think about how sessions work and their relationship with > in-memory objects. You must serialize all the information necessary to > recreate that object in its current state, then handle its corresponding > deserialization. > http://www.php.net/~helly/php/ext/spl/interfaceSerializable.html > http://us.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep > > -Matt > > On Mon, Nov 3, 2008 at 11:03 AM, spaceage <[EMAIL PROTECTED]> wrote: > >> >> I'm struggling with object persistence in sessions...sorry if this is a >> newbie question, but couldn't find answers in the archives... >> >> Basically, I'm loading my namespace session vars; then in my action, I >> check >> if an object exists in the session vars, and if so assign a local >> reference >> to it. If the object isn't in the session vars, I create a new one in >> the >> session vars and setup a local reference. >> >> From testing it appears that I am able to persist non-objects in the >> session >> vars (ie. I can restore an int), but my object isn't persisting between >> requests. My include path for the class ('Album') is ok since I can >> instantiate the object in my code without error. >> >> public function listAction() >> { >> //load collection vars from session >> $sessionVars = new Zend_Session_Namespace('collection'); >> >> //get album from session or create new one >> if (isset($this->sessionVars->album)) >> { >> $currentAlbum = $sessionVars->album; >> } >> else >> { >> $sessionVars->album = new Album(); >> $currentAlbum = $sessionVars->album; >> } >> } >> >> Is there more to "defining the object before the object is unserialized >> from >> session storage" (from docs) than ensuring the class definition is found >> in >> the include path? >> -- >> View this message in context: >> http://www.nabble.com/Zend-Session-and-objects-tp20308552p20308552.html >> Sent from the Zend Framework mailing list archive at Nabble.com. >> >> > > -- View this message in context: http://www.nabble.com/Zend-Session-and-objects-tp20308552p20310605.html Sent from the Zend Framework mailing list archive at Nabble.com.
