CodeIgniter Forums
Object storage and retrieval in session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Object storage and retrieval in session (/thread-22263.html)



Object storage and retrieval in session - El Forum - 09-03-2009

[eluser][At!][/eluser]
Hello,

I'm trying to store an entire object, being a custom library (not extending any of CI libraries) to a session, but I' not succeeding.

I get an error from CI saying it can not convert object to string.

I'm using CI version 1.7.1, Apache 2 with CI Sessions set to use Database storage (which works fine under normal uses)

I've applied the patch that was mentioned in earlier post(s) but seems like that did not work as expected.

Another issue I'm having is once I've stored the object to a session how do I retrieve it, correct me if I'm wrong, but storing of the object from the controller with Session lib auto-loaded would be like:

....
//load my library
$this->load->library('custom_library', '','mylibrary');

...
//do stuff with the library
...

//store the library states as the library should be load again on refresh
$this->session->set_userdata('custom_name', $this->mylibrary);

The above does gives an error

another issue I have is retrieving library from the stored session, currently I'm using.

$this->mylibrary = $this->session->userdata('custom_name');


I use to be able to do this with normal PHP sessions so I would assume the logic is the same.


Kindly assist, and thank you in advance.


Object storage and retrieval in session - El Forum - 09-03-2009

[eluser]Wuushu[/eluser]
In your case, do you think serialize it before store and un-serializing it after retrieval would help?


Object storage and retrieval in session - El Forum - 09-03-2009

[eluser][At!][/eluser]
But doesn't CI do that automatically for me, but I shall try that and see of that helps