Welcome Guest, Not a member yet? Register   Sign In
Using core libraries within application/libraries , codeigniter v2.0.2
#1

[eluser]Unknown[/eluser]
Hi all,

I'm trying to use the core session library function from within a new library within the application folder. Even though the session library is included on the autoload array ($autoload['libraries'] = array('database', 'session');), it does not seem to be recognized from within a new controller class within the application/libraries folder.

The following is the constructor for my new library (saved under application/libraries/My_Foobar.php)
Code:
class MY_Foobar extends CI_Controller  {
  private $CI;
  public function MY_Foobar()  {
   parent::__construct();
   $this->CI = & get_instance();
   $this->CI->load->library('session');
  }
  public function is_logged_in(){

}
}

When i try to use the functions within the session library from the new controller, i get the following error:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: MY_Foobar::$session
#2

[eluser]InsiteFX[/eluser]
That's because it knows that it has already been loaded, if you need to use the session library you do this:
Code:
class MY_Foobar extends CI_Controller  {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        $this->CI =& get_instance();

        //$this->CI->load->library('session'); // session library is already loaded!
    }

    public function is_logged_in()
    {
        $logged_in = $this->CI->session->userdata('logged_in');
    }
}

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB