CodeIgniter Forums
Howto apporach the use of parent controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Howto apporach the use of parent controllers (/showthread.php?tid=23266)



Howto apporach the use of parent controllers - El Forum - 10-05-2009

[eluser]dirkpostma[/eluser]
I want to make use of extending controllers from a controller that implements some common methods.

E.g.:

basic_controller.php
Code:
class Basic_controller extends Controller
{
  function Basic_controller()
  {
    parent::Controller();
  }
  
  function some_common_method()
  {
    // Do something common to many controllers
  }
}


main_controller.php
Code:
class Main_controller extends Basic_controller
{

  function Main_controller()
  {
    parent::Basic_controller();
  }

  function test()
  {
    $this->some_common_method();
  }
}


Unfortunately, this generates an error:
Fatal error: Class 'Basic_controller' not found in /Users/dirkpostma/Sites/citest1/controllers/main_controller.php on line 3

I could solve this by adding
Code:
include_once("basic_controller.php");

...but this is not really the CI way.

Now the (simple) question: what is the CI way of solving this problem...?


Howto apporach the use of parent controllers - El Forum - 10-05-2009

[eluser]dirkpostma[/eluser]
Sorry, I searched before, but didn't find this thread yet:

http://ellislab.com/forums/viewthread/68446/

Now I did, so this one can be closed.