![]() |
Loader::_ci_load_class can't find extended 'MY_' libraries when using $_ci_library_paths - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Loader::_ci_load_class can't find extended 'MY_' libraries when using $_ci_library_paths (/showthread.php?tid=60426) |
Loader::_ci_load_class can't find extended 'MY_' libraries when using $_ci_library_paths - El Forum - 03-24-2014 [eluser]maikens[/eluser] I have a CI install with 2 apps in it, plus a 'common' folder which holds shared models, libraries, helpers the two apps need to use. Code: application/ In order to load everything up correctly in the system Controller.php file, I extend it using core/MY_Controller. I do this in the MY_Controller construct like so: Code: public function __construct() { I also extend Loader in the same manner, so I can add_package_path prior to instantiating the Controller class (it would throw an error when trying to load config before calling Controller::__construct(), so I override add_package_path to allow loading specific things - in this case, models, helpers, and libraries') The problem is, in Loader::_ci_load_class(), when it goes through the _ci_library_paths array to search for the library, it doesn't try appending the 'MY_' prefix when searching, and so it is not loaded as an extension of the Session class. Relevant code in Loader::_ci_load_class() below: Code: // We'll test for both lowercase and capitalized versions of the file name This feels like a core bug to me, but perhaps the way I override or load the Loader class / add_package_path method is wrong? PS my CodeIgniter version is 2.1.0 Loader::_ci_load_class can't find extended 'MY_' libraries when using $_ci_library_paths - El Forum - 03-25-2014 [eluser]jonez[/eluser] Put die statements in each step to see where your conditions aren't catching the correct files/paths. It's not a core bug since it functions correctly without your modifications. Loader::_ci_load_class can't find extended 'MY_' libraries when using $_ci_library_paths - El Forum - 03-25-2014 [eluser]maikens[/eluser] I resolved this by overriding _ci_load_class - simply a copy/paste of the superclass method with this modification: Code: // We'll test for both lowercase and capitalized versions of the file name COMMONPATH resolves to application/common. It couldn't find the subclasses because it was looking in the wrong place. The whole point of add_package_path was to add that place to look, so I find it a little odd that they don't check the _ci_library_paths at this point in the method... but then again my modifications are a little different than what the core developers seemed to have intended for add_package_path(). |