Situation: It seems impossible to store any objects in the CI_Session since, reading them results in the PHP_Incomplete_Object exceptions, as the session is always started, before loading the models.
This way, even when autoloading the Type of object, I am never able to read the data from the session.
I also tried using the “Native Session”, but there it’s exactly the same problem.
Furthermore I tried storing the object serialized, but when unserializing long after having all the models loaded, it still becomes an object with type “__PHP_Incomplete_Class “.
Anyone know a workaround? And please keep “why would you want an object in the session” answers. Seen enough of those …
Unfortunately, php does not allow you to serialize references to one object from another. This is why when you restore your object it does not contain the data it started with.
The best solution I have come up with is to create a Session object in my model layer which is restored using a cookie. The session table in your database handles the references to the objects that you would otherwise have serialized. Once your Session model is loaded, you can use it to load the ‘session stored’ objects, eagerly or lazily.
Further, should these objects hold references to other model objects you can use the same principle to traverse the rest of the model layer, based on the relational references. This can seem daunting, but there are a number of ORMs you could check out if you dont feel comfortable implementing it yourself.