Reputation: 705
I have been trying to use namespaces for the first time in ages and I am running into the below problem. I am currently using Composer for a PSR-4 autoloader and I keep getting the error:
Fatal error: Class 'API\Library\Config' not found in C:\wamp64\www\project\src\index.php on line 14
composer.json
"autoload": {
"psr-4": {
"API\\": "src",
"API\\Library\\": "src/Library",
"API\\Controllers\\": "src/Application/Controllers"
}
}
src/index.php
namespace API;
include_once('vendor/autoload.php');
use API\Library\Config;
$config = new Config(); //line 18
The Folder layout is as such:
Upvotes: 1
Views: 1253
Reputation: 46602
Its because src is the parent folder. Ideally vendor would be in the same directory as src.
"autoload": {
"psr-4": {
"API\\": "",
"API\\Library\\": "Library",
"API\\Controllers\\": "Application/Controllers"
}
}
Would work, or you should restructure your directories.
Also you can leave out "API\\Library\\": "Library",
as it will be picked up by "API\\": "",
Upvotes: 2