Greetings to all, I come again with a problem that I have with self-loading classes with spl_autoload.
This is my Autoloader class:
class Autoloader {
static public function CargarClases($className) {
$filename = "../classes/" . str_replace('\', '/', $className) . ".php";
if (file_exists($filename)) {
include($filename);
if (class_exists($className)) {
return TRUE;
}
}
return FALSE;
}
}
spl_autoload_register('Autoloader::CargarClases');
This is a code that I got and it worked fine, but when I changed the code to use ajax and made a directory of drivers I stopped working, I do the class include in my index.php file, but I have had to add the include autoloader in the controllers, in each of them I do this:
require_once("../classes/Autoloader.php");
I do not know what I'm failing, what is the best practice to place this file and where to include it, I'm a little lost with this topic.
Greetings and I hope you can help me