• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want create a Typical Controller and extends all controller from it, but CI don't find


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.

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


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 ?)

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:

Class MY_Controller extends CI_Controller
    function MY_Controller()
        /* Perform Actions here that All Controllers will need. */


    function require_admin()
        /* Perform actions here required for using admin pages. */


Then on your Admin Controller do something like this:

Class Admin extends MY_Controller
    function Admin()
        $this->require_admin(); /* This makes sure our user has admin privileges. All functions within this controller will now run this.*/


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 author="Kaosland" date="1264665649"]
So someone can tell me how i do for working.[/quote]

Have you tried this ?

[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:


Should be this instead:



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

FrontController extends controller and AdminController extends controller

Thank everyone for your help

[eluser]Phil Sturgeon[/eluser]
Actually you should be using:

// or

Combine that with the __autoload function and you are good to go.

For my dev in localhost
function __autoload($class)
if (file_exists(APPPATH."controllers/".strtolower($class).EXT))

But online i have
can't redefien _autoload.
somebody can help me.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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