I want create a Typical Controller and extends all controller from it, but CI don't find |
[eluser]Kaosland[/eluser]
Hello I create a controller with fonction i call frontcontroller beccause many page don't change almost. Class FrontController exends Controller{ function __construct() {...} function 1; function 2; function 3; } I have place un controller rep, i tested un lib rep with $this->loadlib... but when I want create one controller exends FrontController, i have error Fatal error: Class 'FrontController' not found. So someone can tell me how i do for working.
[eluser]Cro_Crx[/eluser]
You need to create a MY_Controller class which extends Controller. From there all classes will be able to extend it. You can't just write any class and hope that CI can find it as only the required controller is automatically loaded according to the filename. In your case CodeIgniter doesn't know where the FrontController class is when its looking to extend it. Here's some more info: http://ellislab.com/codeigniter/user-gui...asses.html
[eluser]Kaosland[/eluser]
Thanks. I had testing that but don't work, atal error: Class 'CI_Controller' not found . PS with MY_*** I can create only typical class, But I want a controller for Front and a controller for back so 2 controller. (MY_MY ?)
[eluser]Cro_Crx[/eluser]
Make sure that your MY_Controller is extending CI_Controller and your other classes extend MY_Controller. You'll get that error if one of your regular controllers tries to extend CI_Controller instead of its alias 'Controller'. If you want to achieve this functionality, you can do it with a single MY_Controller class. Simply add a function to use if it's an admin page. Something like this for the Base Controller: Code: Class MY_Controller extends CI_Controller Then on your Admin Controller do something like this: Code: Class Admin extends MY_Controller
[eluser]Unknown[/eluser]
It seems that, the code doesn't work...It needs a little changes for it...but I like the topic because it is very useful but not so familiar to me...
[eluser]Cro_Crx[/eluser]
[quote author="Mic2x" date="1264693315"]It seems that, the code doesn't work...It needs a little changes for it...but I like the topic because it is very useful but not so familiar to me...[/quote] Oh yeah, sorry the line: Code: parent::Controller(); Should be this instead: Code: parent::CI_Controller();
[eluser]Kaosland[/eluser]
Thanks But when i use exends CI_controller have again non found CI_contoller. But I use the solution of n0xie that work, and I prefer because I can do FrontController extends controller and AdminController extends controller Thank everyone for your help
[eluser]Phil Sturgeon[/eluser]
Actually you should be using: Code: parent::MY_Controller(); Combine that with the __autoload function and you are good to go.
[eluser]Kaosland[/eluser]
RE For my dev in localhost using function __autoload($class) { if (file_exists(APPPATH."controllers/".strtolower($class).EXT)) { require_once(APPPATH.'controllers/'.strtolower($class).EXT); } } Work. But online i have can't redefien _autoload. somebody can help me. |
Welcome Guest, Not a member yet? Register Sign In |