Welcome Guest, Not a member yet? Register   Sign In
Clarification about MY_Controller and relative inheritances
#1

Hello there.

I need a clarification about the use of MY_Controller and their inheritances.

In my application I'm developing, I have a controller file named MY_Controller with a class

Code:
MY_Controller extends CI_Controller

In the same file I have others two classes, the first one:

Code:
Backend_Controller extends MY_Controller


and

Code:
Frontend_Controller extends MY_Controller

After, I have a series of other controllers extending the two previous classes.

And here I need the clarification: inside the construct function Backend_Controller, I call
a general model in this way:

Code:
Class Backend_Controller extends MY_Controller {
    public function __construct()
   {
       parent::__construct();
       $this->load->model('Auth_Model');
   }

after for example, I have:

Code:
Class Dashboard extends Backend_Controller {
    public function __construct()
   {
       parent::__construct();
   }

   public function index()
   {
       $content = $this->Auth_Model->is_logged_in();
   }
Inside the index function, I call a function contained by the Auth_Model called previously in Backend_Controller,
But I receive an error. I thought that for putting model call inside the constructor of class father, also class child inherits that call.

It works only if I call another time the model inside the function:

Code:
Class Dashboard extends Backend_Controller {
    public function __construct()
   {
       parent::__construct();
   }

   public function index()
   {
       $this->load->model('Auth_Model');
       $content = $this->Auth_Model->is_logged_in();
   }

What's wrong? My knowledge about the inheritance or I'm wrong something in the code?

Just for to learn more about.

Thanks in advance

Giorgio
Reply


Messages In This Thread
Clarification about MY_Controller and relative inheritances - by gbwebapps - 04-17-2017, 07:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB