Welcome Guest, Not a member yet? Register   Sign In
Better Autoloading - Extending core/MY_Controller.php
#4

(This post was last modified: 09-02-2015, 10:34 AM by BrendanRehman.)

(09-02-2015, 06:37 AM)mwhitney Wrote: It would probably be a good idea to add some code at the beginning of that autoloader to skip loading CI_ prefixed classes (and possibly classes with the configured subclass_prefix) to avoid causing issues when those classes are passed to your autoloader (for instance, when someone calls class_exists() without passing FALSE to the second parameter).

Also, a little trick you can use if you don't intend to use Composer is to set the 'composer_autoload' value in your config file to a path to a script registering your autoloader. Then you don't have to mix configuration and code in your config file.

I'm not married to the code, please feel free to fork the code and submit a PR or pop the snippet of code you want me to add here and I'll gladly add it. I had planned on writing a post for Composer setup and autoloading but perhaps next time... Smile

PS

Thanks for the hint on composer_autoload in config.php, I learned something new today. I was gonna include the autoload file from the vendor folder so this keeps the config file cleaner.

Thanks,
Brendan
Reply


Messages In This Thread
RE: Better Autoloading - Extending core/MY_Controller.php - by BrendanRehman - 09-02-2015, 10:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB