I writing a smal php mvc framework, and i want to autoload my clases like Controller, Model etc.For that purpose iam try to use UniversalClassLoader from Symfony and he just wont load classes, and when i try to use them i get this error
Fatal error: Class 'APP\Libraries\Controller\Controller' not found in /opt/lampp/htdocs/web/globeapi/Bootstrap.php on line 24
here is Bootstrap.php
require('../libraries/loader/UniversalClassLoader.php');
use Symfony\Component\ClassLoader\UniversalClassLoader;
class Bootstrap
{
function Bootstrap()
{
}
public static function run()
{
$auto = require('../config/Auto.php');
$SPL = new UniversalClassLoader();
$SPL->registerNamespace('APP\Libraries\Controller', '../libraries/controller/Controller.php');
$SPL->register();
APP\Libraries\Controller\Controller::test();
}
}
here is Controller.php
namespace APP\Libraries\Controller;
class Controller
{
function __construct()
{
echo 1;
}
public static function test()
{
echo 1;
}
}
I have also tryed MapClassLoader but the result is same.
I think you only need to register the main namespace. The second parameter needs to be a path and not a file. Also try with absolute not relative path. The next problem is that your directories are lower case. So the autoloader is expecting the path LIB_FOLDER/APP/Libraries/Controller
for a namespace APP\Libraries\Controller
. I don't know if you can set aliases for converting lowercase to uppercase. But it dosn't seem so.
Try something like that:
$SPL->registerNamespace('APP', __DIR__.'/../LIB_FOLDER');