That makes perfect sense (each object calling its own serialize method(s))...
I learned that omitting the __sleep method in the object will result in all properties getting serialized (as one would expect from $_SESSION functionality). My issue seems to be that I had a Zend_Db_Select object as a property in my object. Apparently it can't serialize, so my entire object fails to write to the $_SESSION (???). I rewrote the code to store the search parameters from my Db_Select object in an array in the namespace. I reconstruct my Select object on the page request based on the persistent search parameters. It works fine--the search parameters array (and the rest of the object) persists in the namespace. I was hoping to keep the Zend_Db_Select object around between requests so I could save the overhead of rebuilding it, but no big deal. I'm assuming I need to do something like extend the Zend_Db_Select class to add a __sleep method??? Or is there an easier way? Thanks for your help! Matthew Ratzloff wrote: > > a) A->B->C: A has object B has object C. A's serialization method should > call serialize() on B. B's serialization method should call serialize() > on > C. The only automatic aspect is that serialize() called on an object > calls > its __sleep() method. > b) Not sure. I'll let Ralph or someone else answer that question. > > -Matt > > On Mon, Nov 3, 2008 at 12:52 PM, spaceage <[EMAIL PROTECTED]> wrote: > >> >> 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. >> >> > > -- View this message in context: http://www.nabble.com/Zend-Session-and-objects-tp20308552p20316348.html Sent from the Zend Framework mailing list archive at Nabble.com.
