Welcome Guest, Not a member yet? Register   Sign In
Sessions, not readable in constructor.


I got a problem with sessions. The problem is that the sessions is not readable in a library constructor.

My autoload:
$autoload['libraries'] = array(

My Auth class (where the problem occurs):
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!):
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.

What happens when you:


In the constructor?

Oh, all_userdata() worked. My bad, ofc it was the config file that was not loaded!
Thank you.

Always something simple :o)

Theme © iAndrew 2016 - Forum software by © MyBB