I have a issue with my autoloader. I am working with namespaces and routing, now is the problem that I can autoload my classes but then I can't autoload my controllers.
I build my autoloader like this now:
function __autoload($class)
{
$parts = explode('\\', $class);
$path = './'.end($parts).'.php';
if (file_exists('./'.end($parts).'.php')){
require $path;
}else if (!file_exists('./'.end($parts).'.php')){
$path = '../Controller/'.end($parts).'.php';
require $path;
}
}
I can't come up with another idea to do this.
BTW, my autoloader is in my 'init.php' and that is in my Core folder where I also store all my classes. But my controllers are in a different folder named 'Controller'.
But with this autoloader concept I get this error:
Warning: require(../Controller/App\Core\Route.php): failed to open stream: No such file or directory in D:\App\Core\init.php on line 28
Fatal error: require(): Failed opening required '../Controller/App\Core\Route.php' (include_path='D:\Xampp\php\PEAR') in D:\App\Core\init.php on line 28
It wants to open my Route class out of the Controllers folder, but the Route class is in my Core folder.
Someone an idea?
Comments
Post a Comment