I have been trying to override the “database” method of the loader class (CI_Loader). I followed the instructions found on the CodeIgniter user guide: Creating Libraries (scroll to “Extending Native Libraries”). But MY_Loader class does not load automatically and is not used in $this->load calls in place of the CI core Loader class.
I’ve only created MY_Loader class (application/libraries/MY_Loader.php as specified in the user guide). Is there something I’m missing?
I’ve tried to put it in config/autoload.php for the libraries section of that file, and it indeed is autoloaded, but then I access to the library using $this->my_loader->database() and that’s not the idea…
I paste below the content of application/libraries/MY_Loader.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Loader extends CI_Loader {
function database($params = '', $return = FALSE, $active_record = NULL)
{
echo '---test---';
exit;
}
}
Thank you very much.
The loader class is part of the core so it needs to go in “application/core/MY_Loader.php”
Any class you wish to extend should go in the corresponding directory in your applications folder. You should be able to take the class you wrote, drop it in there, and presto…it should work. No hacking required.