4

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 Answers 3

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I am calling that. Only problem is that I am not able to load library from grand child.
1

Checkout CodeIgniter Base Controllers, explanation included.

Comments

0
//-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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.