CodeIgniter Forums
Extending admin controllers from a general controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Extending admin controllers from a general controller (/thread-18219.html)



Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]Bramme[/eluser]
Hey all

I'm working on an app that has a series of frontend controllers and a series of backend controllers. All backend controllers share a set of common functions in the construct that are copy pasted in all controllers.

If it weren't for the frontend controllers, I would simply create a MY_Controller library and put the functions there, but this is no option, as those function can't be executed for the frontend controller (authentication etc).

This is why I created a Admin_controller library, extending Controller and I extend my backend controllers from this Admin_controller library (I had to include the Admin_controller.php in the top of the page to get it to work, but that's the least...)

However, I now notice that my libraries (that I load in Admin_controller) aren't loaded at all... (I get an error, call to a function on a non-object).

So my question is:
Has anybody gotten this to work in the past

OR

Is there a safe way of retreiving what controller is accessed in MY_Controller, so I could work with an if there. $this->uri->segment isn't safe enough, because some controllers are bypassed by routes.


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]xwero[/eluser]
why not create a backend helper?


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]wiredesignz[/eluser]
Quote:... I would simply create a MY_Controller library and put the functions there, but this is no option, as those function can’t be executed for the frontend controller (authentication etc).

You may put more than one controller base class inside the MY_Controller.php file.


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]Bramme[/eluser]
Thanks for the fast replies!

I've decided to work with a MY_Controller extending CI_Controllers, however, suddenly I get an error:

Fatal error: Class 'CI_Controller' not found in C:\Users\Bram\Websites\Projects\simplecms\application\libraries\MY_Controller.php on line 3


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]wiredesignz[/eluser]
There is no CI_Controller class, simply use Controller.

Good luck.


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]xwero[/eluser]
Controller and Model are the only classes that have no CI_ prefix.


Extending admin controllers from a general controller - El Forum - 04-29-2009

[eluser]Bramme[/eluser]
Crikey, it's been a while! :p


New error: the library isn't loading Sad


edit: Note to self: check the user guide better

Code:
class Welcome extends MY_Controller {

    function Welcome()
    {
        parent::MY_Controller();
    }

    function index()
    {
        $this->load->view('welcome_message');
    }
}