Decode
Decode

Reputation: 160

Can't load my custom library codeigniter 3.0

I am a newbie of codeigniter. in codeigniter v3.0, I try to load my custom library. but it seem not work.

This is my source code.

Library

class MY_Login extends CI_Controller{

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

        // call with constructor.
        $this->isLogin();
    }

    function isLogin() {
         //source code
    }  
}

Controller

class Dashboard extends CI_Controller {

    protected $CI;

    public function __construct()
    {
        parent::__construct();
        $this->load->library("MY_Login");
        $this->CI =& get_instance();
    }
}

Any help would be appreciated :)

Upvotes: 1

Views: 4346

Answers (3)

Vinie
Vinie

Reputation: 2993

For Library you don't need to extend CI_Controller. Just write the class name. Place this file in application/libraries

class MY_Login{
  protected $CI;
  function __construct() {
       // call with constructor.
      $this->isLogin();
  }

  function isLogin() {
     //source code
  }  
}

Now for controller Dashboard.php

class Dashboard extends CI_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->load->library("MY_Login");
    }
}

This will work fine. Please try it.

Upvotes: 0

user4419336
user4419336

Reputation:

A codeigniter library file goes in application > libraries > My_login.php you do not need extend CI_Controller just class

class My_login {

    function __construct() {
        $this->CI =& get_instance();

        $this->isLogin();
    }

    function isLogin() {
         //source code
    }  
}

Controller

class Dashboard extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->library("my_login");

}
}

When you use MY_Controller in application > core

<?php

class MY_Controller extends CI_Controller {

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

}

Controller extending core MY_Controller

class Dashboard extends MY_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->library("my_login");

}
}

Upvotes: 2

Bipin Kareparambil
Bipin Kareparambil

Reputation: 473

Place MY_Login Controller in Core folder. then,

class Dashboard extends CI_Controller {

protected $CI;

  public function __construct()
  {
    parent::__construct();
    $this->CI =& get_instance();
  }  
}

Upvotes: 0

Related Questions