4
votes

I am having problem in using multilevel inheritance as follows.

I have a top level controller that extends CI_Controller class

class Application extends CI_Controller
{
}

A controller named 'Site' and 'Admin' extends the Application controller as

class Site extends Application
{
}

class Admin extends Application
{
}

And finally class 'User' and 'Guest' extends 'Site' controller

class User extends Site
{
}

Class Guest extends Site
{
}

The problem is, in User and Guest controller I am not able to load core libraries such as pagination, form_validation etc. using

$this->load->library('pagination);

But it works when I load the library in Site controller or Application contoller ie. controller that extends the core CI_Controller and it's child controller. When I try to load in grand child it doesn't work.

Can somebody clarify why this is happening? Thanks...

3

3 Answers

2
votes

I've not seen a multi-level constructor class set up before, but it should work.

Are you calling parent::__construct() in the constructor of each class?

1
votes

Checkout CodeIgniter Base Controllers, explanation included.

0
votes
//-Create MY_Controller.php on application/core/MY_Controller.php
//contents of MY_Controller.php
class Application extends CI_Controller{
    function __construct(){
      // Call the CI_Controller constructor
      parent::__construct();        
    }
}
//that is all now you can inherit class (Application) anywhere in your project