Search code examples
phpnamespacesautoloader

Error accessing class when using Composer autoloader


I have folder app/Controllers/HomeController.php and in my composer autoloader i write like this:

"autoload": {
        "psr-4": {
            "App\\": "app/",
        }
    },

but when i try to access my file from public/index.php like this:

require __DIR__ . '/../vendor/autoload.php';

$home = new \App\Controllers\HomeController;

I got some error like this:

Fatal error: Uncaught Error: Class 'HomeController' not found in E:\laragon\www\slim\public\index.php:14 Stack trace: #0 {main} thrown in E:\laragon\www\slim\public\index.php on line 14

so where i'm doing wrong here? for more info in my HomeController i using namespace like this:

namespace App\Controllers;

Solution

  • Ok the answer is I have to dumb my autoloader and it works.