0

I'd like to extend CI_Controller further, but within the controllers folder.

I already have a subclass MY_Controller in application/core/MY_Controller.php, and I know already I can add new subclasses of MY_Controller in the same file.

My question is, how to extend MY_Controller further by adding files in the controllers folder? For example:

class Comm_Controller extends MY_Controller{}

class ServiceA_Controller extends MY_Controller{}
// or even
class ServiceAplus_Controller extends ServiceA_Controller{}

If I do not modify the autoload, it will report "class ServiceA_Controller not found", but I would prefer not to add any other file to the application/core/ folder.

Pietro Saccardi
  • 2,602
  • 34
  • 41
Rex
  • 76
  • 10
  • You don't need to add 'subclasses', but you need to add new files in core directory. CodeIgniter reads files/classes from core directory, not from controllers directory. Check code in `BASEPATH . 'core/CodeIgniter.php'` file around line 370 I'd say. Other way to use it is composer autoloading classes. – Tpojka Sep 15 '15 at 14:19
  • possible duplicate of [Extending The Controller Class in CodeIgniter](http://stackoverflow.com/questions/8342232/extending-the-controller-class-in-codeigniter) – Abdulla Nilam Sep 16 '15 at 04:21
  • @Abdulla That solution must put the base controller in core/ file. I've already mentioned. – Rex Sep 16 '15 at 09:01
  • @Tpojka Put the business code in core may be a little inelegant? – Rex Sep 16 '15 at 09:03
  • @Rex Otherwise you need to make your own bridge for wanted solution. I showed you snippet location where CI takes it from. If you don't like CI's logic of files/directories organization, you would be liking to use some other FW or solution. Aside that, I can't see one reason for avoiding core or library directory. – Tpojka Sep 16 '15 at 09:09
  • Thanks @Tpojka. I think I need HMVC support for CI. – Rex Sep 17 '15 at 11:21

0 Answers0