I want to load HomeController class from lib
directory:
root/
-lib/
--/HomeController.php
-vendor/
-composer.json
-index.php
Composer.json
"autoload": {
"psr-4": {
"Lib\\": "lib/"
}
}
HomeController.php
namespace Lib;
class HomeController {}
index.php
var_damp(new \Lib\HomeController.php);
It doesn't find the class.
But if I put HomeController.php inside Controllers directory:
root/
-lib/
--/Controllers/HomeController.php
And update the namespaces: index.php to var_damp(new \Lib\Controllers\HomeController.php);
and HomeController.php to:
namespace Lib\Controllers;
class HomeController {}
It works perfect.
It's weird, I can't find any docs talking about it. I don't need additional directories, in this case I want the HomeController class directly inside lib
directory.
How can I make it works inside lib
folder?