(02-02-2016, 11:54 AM)jlamim Wrote: Today I was approached by a student of mine who is starting in CI and he asked me a question that I was right in question to answer. He wants to extend a controller, in the following situation:
Father Controller -> class extends Person CI_Controller
Controller son -> class PersonEspecial extends Person
However, he only managed to make it work by putting the controller in the parent directory 'core'. He would like to extend the controller maintaining the controller in the parent directory 'controllers'.
I found no reference in the documentation and I wonder if anyone could give an answer on the issue.
It can extend a controller even though he was within 'application / controllers'?
My question had strong similarities to this one so I figured I would ADD mine in hopes of ideas.
I understand that CI_Controller is the base controller provided by CodeIgniter and that we can extend this base controller with our own version named MY_Controller (MY_ being a defined prefix of the config.
My objective is two have TWO custom base controllers:
MyCustomFrontController
This BASE controller is pretty much what I would have put in the classic MY_Controller and then used it as the BASE for all my regular controllers. This controller is specialized to handle my USER AUTHENTICATION needs.
MyCustomAPIController
This BASE controller would be used for controllers that are in fact services exposed as RESTful APIs and used as the BASE for all my services. Handling for example HTTP BASIC AUTHENTICATION commonly used in API calls.
My Controller inheritance tree would look like this:
CI_Controller
MyCustomFrontController
News
Login
About
MyCustomAPIController
MembersDirectoryService
ActiveUserListService
Any tips on how I could achieve this cleanly?
So far, I am tempted to alter part of the CI core code to add support for multiple base controllers.
Thanks in advance for any tips, this is my first forum post :-)