Welcome Guest, Not a member yet? Register   Sign In
Object storage and retrieval in session


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.

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

But doesn't CI do that automatically for me, but I shall try that and see of that helps

Theme © iAndrew 2016 - Forum software by © MyBB