Fatal error when extending a Controller, not found |
[eluser]Isern Palaus[/eluser]
Hello, I'm trying to extend a controller and I get a not found. My idea is to have BackendController and FrontendController that extends MY_Controller, all in /libraries. In my controllers I will extend Front or Backend depending of the kind of controller. /libraries/MY_Controller.php Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); /libraries/BackendController.php Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); /controllers/admin/test.php Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); And my final result: Fatal error: Class 'BackendController' not found in /var/www/testapplication/src/application/controllers/admin/test.php on line 4 How I can solve it? If I use MY_Controller works fine... Thanks in advance!
[eluser]Phil Sturgeon[/eluser]
You've missed out the autoload. A class wont exist if you dont include it somehow. http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
[eluser]Isern Palaus[/eluser]
Was some months without CI and didn't remembered why the other times worked. Now I remember! Thank you! :-)
[eluser]Bramme[/eluser]
Gonna dig this up a little, just wanna check. I have extended CI_Controller by adding MY_Controller.php in application/libraries/ Code: class MY_Controller extends CI_Controller { I extend my controllers from MY_Controller instead of CI_Controller, however, without adding following code (from the link above), I get a "Class 'MY_Controller' not found". So this is "normal" behavior? I'm using CI2.0, shouldn't that autoload function be added to the core version then? |
Welcome Guest, Not a member yet? Register Sign In |