2

I have two namespaces in my session: "global" and "user"

In "global" there are just a few settings and in "user" i have a serialized user-object which I guess is saved correctly: (This is from the sessionfile)

global|a:16:{ [...] s:12:"last_request";i:1301390173; [...] }

user|a:1:{ s:10:"userObject";O:16:"currentUserModel":24:{ [...] s:10:"*_roleId";s:7:"premium"; [...] } }

When I do this: $sess = new Zend_Session_Namespace('global');

I get an error about including "currentUserModel.php" which I don't want because I don't need the userobject at this point - all I want to do is get my "global" namespace.

Now the question is: Do I have to include all classes for all objects stored in all my namespaces or is it possible to include just the classes for the objects that are in the namespace I'm accessing?

Thanks in advance

Philipp Horn
  • 568
  • 1
  • 5
  • 12
  • are you using `user` to store `user` session? – S L Mar 29 '11 at 09:45
  • I'm not sure what you mean. "user" is the namespace I made up. "userObject" is the session-variable and "currentUserModel" is the name of my class. – Philipp Horn Mar 29 '11 at 09:53
  • userObject and currentUserModel are saved in the user namespace or in the global namespace looking at you're error i suppose they are in the global namespace, another thing why are you saving the model in you're session ?? – Poelinca Dorin Mar 29 '11 at 10:00
  • They _should_ be saved in the "user" namespace (I edited in a bigger part of the sesionfile). Because of your question I think I just need to save all the data from the userobject and create a new one with that saved data when I need it :) Would this be a good time to use the __sleep() and __wakeup() methods? (I'm pretty new to OOP) – Philipp Horn Mar 29 '11 at 11:32

1 Answers1

2

The namespace in Zend_Session is just a layer on top of the $_SESSION global variable. In php, these namespaces don't exist. In Zend_Session, the namespace is a key from a associate array.

Thus, when you load a session namespace, you load in fact the whole $_SESSION, except you cannot access other "namespaces" through this Zend_Session. So yes: you need to include the file currentUserModel.php before the session.

Another method is to use properly the __sleep() and __wakeup() magic methods from the class to serialize only the properties of a class as an associative array and then you're afaik ready to go.

Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99