Welcome Guest, Not a member yet? Register   Sign In
Will this work?
#1

[eluser]doors[/eluser]
$CI =& get_instance();

$CI->load->library('App');

$this->application = clone $CI->app;

$CI->session->set_userdata('app', $this->application);
#2

[eluser]tonanbarbarian[/eluser]
it seems you are cloning for no real benefit
all that will do is use more memory
why not just
Code:
$CI =& get_instance();

$CI->load->library(’App’);

$CI->session->set_userdata(’app’, $CI->app);

and is there a reason why you are using get_instance rather than $this, are you calling this from a library for example?
#3

[eluser]doors[/eluser]
I am using it from a library.

The thing is that the session is not displaying the object. I can't call the objects functions. Why would that be.

I cloned it because I didn't want to pass the object by reference.
#4

[eluser]doors[/eluser]
in my controller I did this:

$this->session->userdata('cart')->test();

Which is suppose to print: "Test function loaded".


I am getting no output.
#5

[eluser]thurting[/eluser]
serialize()?
#6

[eluser]doors[/eluser]
serialize what and how?
#7

[eluser]tonanbarbarian[/eluser]
ok first thing is why do you want to pass an object to the session?

session is only able to handle simple types like string and simple arrays
if you want a complex type you need to serialise it before you send it and then unserialise it afterwards

however you also have to be aware that objects sometimes need special actions before or after serialising

to serialise you do the following
Code:
$CI =& get_instance();

$CI->load->library(’App’);

$this->application = clone $CI->app;

$CI->session->set_userdata(’app’, serialize($this->application));

You will need to call unserialise again when you read it back

BUT

my advice is do not do this if you do not need to
technically you could serialise a large number of the classes and objects in CI and store them in a session then unserialise them on the next request and that "might" improve the performance a little bit
but generally it is not worth the effort
#8

[eluser]doors[/eluser]
[quote author="tonanbarbarian" date="1202806002"]ok first thing is why do you want to pass an object to the session?

session is only able to handle simple types like string and simple arrays


[/quote]

Php built in sessions can hold objects so why change it. That makes no sense.

Well I am now using the NGSession class file which does the serialize and unserialize and stores my objects in the database. This makes sense.

so this now works:

Code:
$CI->load->library(’App’);

$this->application = clone $CI->app;

$CI->session->set_userdata(’app’, $this->application);




Theme © iAndrew 2016 - Forum software by © MyBB