How to load the db class after the session in CodeIgniter
Question by yeah its me
when i want to make a foreach($_SESSION[‘banners’]->result() as $banner), i get this error:
The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CI_DB_mysql_result" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in….
how can i load the db class after the session, i am using the native session $_SESSION, i dont want to use the codeigniter sessions because they have problems in IE, how can i resolve this problem?? or what function i need to use to load the DB class after the session in CI?
Answer by Starx
Use the native Codeigniter Session, to avoid such problems. To fix the problem with IE, make the following changes on config.php
$config['sess_cookie_name'] = 'ci_session';
to
$config['sess_cookie_name'] = 'cisession';
-
Initiate the library like this
$this->load->library('session');
-
Set data in the session like this
$this->session->set_userdata('item', 'value');
-
And read the values like
$this->session->userdata('item');
Then on your application you will able to use it like this
foreach($this->session->userdata('banners') ->result() as $banner) {}