Welcome Guest, Not a member yet? Register   Sign In
Session - Object Serialize Problem
#1

[eluser]Multisnet[/eluser]
Hello,

I'm facing a problem when I try to serialize an object and use it in a CI base session. Someone have this working?

A brief example of my code.

In the same controller:

Code:
function Page1(){
$this->load->model('people', 'people');
$this->people->definePeople(...);
$people_serialized = array('people_s' => serialize($this->people));
$this->session->set_userdata($people_serialized);
}

function Page2(){
$this->load->model('people', 'people');
print_r($this->session->userdata('people_s'));
}

It prints nothing! However if I change the $people_serialized = array('people_s' => 'TEST!!!!!') in the second page it prints the word "TEST!!!!!!".

Is it possible to use serialization on CI Sessions? Please help me.. I'm tired of trying to resolve this :down:

Thanks in advance
#2

[eluser]Multisnet[/eluser]
I solved my problem using the EckoSession available at EckoSession.
#3

[eluser]sl3dg3hamm3r[/eluser]
[quote author="Multisnet" date="1246308857"]I solved my problem using the EckoSession available at EckoSession.[/quote]

Since version 1.7, CI also supports sessions in a DB-table, natively. No need for this library. I guess your serialized object got too long (> 2KB), that's why it can't be transfered anymore with a cookie.

See chapter "Saving Session Data to a Database" here.
#4

[eluser]TheFuzzy0ne[/eluser]
Also, have you overridden the session class at all? Often I'll debug some code and forget I've left an echo statement in there somewhere.
#5

[eluser]Chad Fulton[/eluser]
I think it is likely that you may be running into the 4kb size limit on session data. When I tested this by serializing one of my own CI objects, I got a 49kb string, although depending on your configuration it might be less for you.

There are a couple of potential solutions:

(1) You could use send only the actual data, and reconstitute the People model on the other side.
(2) You could load the People class by $this->people = new People(); rather than loading it as a model, and then, in the People constructor, call $this->ci =& get_instance(); and make all of the calls in the People model go through $this->ci->db->... or whatever. Then, you could define an __sleep() function which dereferenced the $this->ci variable ($this->ci = null), and an __wakeup() function which reconnected it ($this->ci =& get_instance()Wink

I suspect (1) would be easier / better, if possible.




Theme © iAndrew 2016 - Forum software by © MyBB