Answer the question
In order to leave comments, you need to log in
How to add another directory to autoloader in CodeIgniter?
Good afternoon.
I am refactoring a project on codeigniter. I want to enter traits and load them automatically accordingly.
How to add a traits directory and explain to the framework so that it can also load files from there as well as with libraries and with models...?
I really don't want to edit Core\Loader.php.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
In short, I got out of the situation so far in this way: I added the code to the end of the Config/autoload.php file
spl_autoload_register(function($class) {
if (substr($class, -5) == 'trait') {
require_once (__DIR__ . '/../traits/' . $class . '.php');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question