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

[eluser]Unknown[/eluser]
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!

Greetings,
Hendrik
#2

[eluser]danmontgomery[/eluser]
You can't autoload a controller...

http://ellislab.com/codeigniter/user-gui...asses.html
#3

[eluser]Unknown[/eluser]
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?
#4

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

[eluser]danmontgomery[/eluser]
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