[eluser]Unknown[/eluser]
Hi!
I got a problem with sessions. The problem is that the sessions is not readable in a library constructor.
My autoload:
Code:
$autoload['libraries'] = array(
'database',
'layout',
'session',
'auth',
'error'
);
My Auth class (where the problem occurs):
Code:
public function __construct()
{
$this->_ci =& get_instance();
$this->_ci->load->library('session'); // Just to be sure. It may not be in the autoload.
// Loads other stuff.
$this->print_session(); // Does not print anything! $session === NULL.
}
public function print_session()
{
$session = $this->_ci->session->userdata($this->_ci->config->item('auth_session_name'));
echo $session;
}
My controller (where it works!):
Code:
class Users extends MY_Controller {
public function login(){
$this->auth->print_session(); // Prints the content of the session!
}
}
So, why can't I get the session data in the constructor, but I can any time later in the code?
It works in the Auth class if I put it later than the constructor. Like in the destructor.