I'm trying to implement the autoload feature using psr-4 with composer but I get this error, even if I've already require it in the index. Please see the error and code below:
Error
Fatal error: Class 'Blog\Classes\Database\Connection' not found in C:\wamp\www\blog-oop\index.php on line 7
Code
composer.json
{
"autoload": {
"psr-4": {
"Blog\\": "app/classes/Database"
}
}
}
Connection.php
<?php
namespace Blog\Classes\Database;
class Connection{
}
index.php
<?php
require "vendor/autoload.php";
use Blog\Classes\Database\Connection;
$connection = new Connection;
Structure
>app
>classes
>Database
>Connection.php
"Blog\\": "app/classes/Database"should be"Blog\\": "app"as the namespace acts as the path to find the class.