Extending CI_Controller is not working |
[eluser]MartinF[/eluser]
Hello, i am using CodeIgniter 2.0. I have a base controller class ControllerBase (ControllerBase.php) that extends the CI_Controller. I have put this in the application/libraries folder. Code: class ControllerBase extends CI_Controller The idea is that i usually want this to be the class that all my Controllers extends, and I can put all shared functions in only one place. But whenever i try to extend this class (ControllerBase) from one of my Controllers (in application/controllers) i get an error saying "Fatal error: Class 'ControllerBase' not found in......" Code: class Home extends ControllerBase I have registered ControllerBase in the autoload.php Code: $autoload['libraries'] = array('ControllerBase'); The file is being loaded - if i try to echo out something at the top of the file and i dont try to extend it. I have also tried naming the file with the MY_ prefix but it doesnt make a difference, I still get the error message when i try to extend the class. It works fine if I put the ControllerBase class in the same file as the Home class So i suspect it has something to do with the autoloading happening to late in the proccess (after the Home class tries to extend the ControllerBase), or maybe the naming of the file? I assume application/libraries is the correct place to put the file? Anyone who can figure out what i am doing wrong ?
[eluser]InsiteFX[/eluser]
MY_Controller extends CI_Controller - place MY_Controller in application/core Extended Controllers go in application/controllers Home extends MY_Controller Read - Phil Sturgeon's CodeIgniter Base Classes: Keeping it DRY InsiteFX
[eluser]MartinF[/eluser]
Thanks for the reply. Works perfectly. But not quite happy with the file name (MY_Controller) ... but i will live with it. Thanks again.
[eluser]WanWizard[/eluser]
You can change the default 'MY_' prefix to anything you want in the config.
[eluser]ray023[/eluser]
[quote author="InsiteFX" date="1298853162"]MY_Controller extends CI_Controller - place MY_Controller in application/core Extended Controllers go in application/controllers ...[/quote] Should this be a listed step in the upgrading documentation? In 2.01 to 2.02, step 3 mentions that security should be moved...but I don't see any other steps instructiong about what to do with extended controllers.
[eluser]InsiteFX[/eluser]
You need to add this! Code: /* InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |