Welcome Guest, Not a member yet? Register   Sign In
Extending admin controllers from a general controller
#1

[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.
#2

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

[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.
#4

[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
#5

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

Good luck.
#6

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

[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');
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB