storing objects in CI session |
[eluser]stormbytes[/eluser]
Trying to store an serialize($object) in $this->session->set_userdata('object', $object) and then retrieve it in a view using unserialize(). Is there an issue with this approach I should know about? It's not working.. getting errors.
[eluser]stormbytes[/eluser]
Random stuff that didn't make much sense... "incomplete object" etc. The real problem is that I'm not sure how to go about it, so I'm playing guessing games! ughh... How about a tip? I'd like to create an instance of my custom class in a controller method, then save that object in the session and retrieve/use it in another controller method at some later point ![]()
[eluser]Nick_MyShuitings[/eluser]
from another thread (http://ellislab.com/forums/viewthread/173310/): [quote author="WanWizard" date="1289625664"]Are you using cookie-only sessions? And if so, are you storing a lot of data? Cookies have a maximum size of 4Kb. If you encrypt the data, the data increases in size. If it exceeds 4Kb, the cookie gets truncated, which means it can't be decrypted anymore, and all data is lost.[/quote] From the incomplete object error it seems like you might be truncated. I would recommend one of the advanced session libraries, or at the least setting the config to true to have the session stored in the db.
[eluser]stormbytes[/eluser]
I'm storing the session data in db. I think my problem is syntactical. Could you provide some generic example I could follow that would accomplish what I'm trying to do?
[eluser]Nick_MyShuitings[/eluser]
Code: $this->load->library('session');
[eluser]stormbytes[/eluser]
Okay so let me see if I got this... (session loads automatically - I don't think you need to load it) Code: // Assuming a php class - That look right?
[eluser]Nick_MyShuitings[/eluser]
That should do it, I don't see any obvious errors there. Does that throw errors at you? EDIT. you did have a small error at the very end when you try to echo... forgot the $ in front of new_object
[eluser]stormbytes[/eluser]
Well thought I'd run it by you first, but I'll give it a shot now... Do you do freelance work?
[eluser]Nick_MyShuitings[/eluser]
Yeap, Its what puts the bread on the table. And if its CI related its about 900x better then the nasty Drupal/Magento/Symfony work I sometimes have to take... lol ![]() |
Welcome Guest, Not a member yet? Register Sign In |