Welcome Guest, Not a member yet? Register   Sign In
Own base controller in addition to MY_Controller

Hello there,

I'm new to CodeIgniter, so, hello!

I'd like to add another Controller base class like MY_Controller next to it. I've already put a class deriving from Controller into a php file in the application/library folder and inserted the appropriate entry into the autoload.php library-array. But it doesn't work. It somehow conflicts with other libraries that stop working when I add the autoload entry (namely "phpsession" and "Template").

But in my new application/library/...php file there is nothing more than a new class deriving from Controller. Nothing that could conflict with anything else in the CI system, well, at least in my understanding. Even the class name is uniquely chosen. And it calls parent::Controller in its constructor.

I took care to correctly name the file and the class (names are equal and capitalized).

So is this actually the preferred way of adding a new controller base class? Putting it into a library and autoloading it?

Thank you!


You can't autoload a controller...


Okay, thanks. So I can only add ONE extension for every core class type? One MY_Controller, one MY_Input and so on. Right? There is no suitable "CI"-way to add multiple core class "MY_"-like extensions?

You could use autoload. Take a look here or read Phil's guide: http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY

Sorry, I was thinking autoload.php, not __autoload... You can do it that way.

You're not necessarily limited to one extension, you're extending MY_Controller in your controllers, so there's no reason you can't use MY_Admin_Controller, MY_News_Controller, etc. All are extending the Controller class.

Theme © iAndrew 2016 - Forum software by © MyBB