• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extending Controller from a Master Controller

#1
[eluser]Mavrick[/eluser]
Hi every one,

I have created a Master Controller. And I want my other controller's to extend my Master controller. I did tried that but no luck. Is there a way of doing it???

Let me put my Master Controller here:

Code:
<?php
    class Master extends CI_Controller {
        function __construct() {
            parent::__construct();
            $this->load->helper('url');
            $this->load->view('header');
        }
    }
?>

Now What I tried was :
Code:
class My_controller extends Master {....}
But it didn't worked... Can some one tell me a way to this kind of a thing? If its possible Smile

Thanks in advance,

#2
[eluser]Akinzekeel[/eluser]
I usually do it like this:

/application/core/MY_Controller.php
Code:
class MY_Controller extends CI_Controller {

public function __construct() {
parent::__construct();
// your stuff here...
}

// your "Master controller" functions go here...
}

Then in your actual controllers you code like this:
Code:
class some_controller extends MY_Controller {

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

// Your "Master controller" functions are usable within this class!

}

#3
[eluser]Mavrick[/eluser]
But in this case I am getting this error :down:
Fatal error: Class 'Master' not found in D:\wamp\www\Mavrick\application\controllers\sitelinx.php on line 2
line 2 is :
Code:
class Sitelinx extends Master

#4
[eluser]Akinzekeel[/eluser]
Use the class name MY_Controller instead of Master, that should work.

#5
[eluser]Mavrick[/eluser]
OK That Did it!!! :lol: ... But Why Confusedhut:

For e.g: File Name is MY_Master.php under the core directory
Code:
class MY_Master extends CI_Controller
Then why wouldn't it work???

#6
[eluser]danmontgomery[/eluser]
This is covered in the user guide.

#7
[eluser]Mavrick[/eluser]
Noctrum Smile

Thanks Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.