Welcome Guest, Not a member yet? Register   Sign In
Clarification about MY_Controller and relative inheritances
#12

(04-17-2017, 08:53 PM)marksman Wrote: If that the case then would you think how CI include the file of backend/frontend controller without modifying config.php from MY_ convention to your own or by creating your own autoloader inside MY_Controller

I'm not sure I understand the above statement. I think you're asking, "How do you include individual child class files without using $config['subclass_prefix'] or an autoloader?" If that's what your asking then you're left with using "include" or "require" to manually load the files i.e.
PHP Code:
include_once(APPPATH.'libraries/Backend_Controller.php'); 
   

One of Avenir's tutorials shows multiple ways to handle extending CI_Controller multiple times or even how to create multiple "base" controllers.

My preference is an autoload function inside a hook. That approach means you can use "the codeigniter way" when loading classes and maintain the best practice of one class per file. It also means you can abandon the use of $config['subclass_prefix'] all together and put all your child class files (including any that subclass CI_Controller) in the application/libraries/ folder.

I often find the need to subclass custom libraries that are not children of CI_Controller. But because of its design CI cannot load a subclass of a custom library - it can't find the parent file. That means either resorting to include/require or an autoloader.
Reply


Messages In This Thread
RE: Clarification about MY_Controller and relative inheritances - by dave friend - 04-18-2017, 07:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB