MVC using composer autoload psr-4 is not worked for me

Viewed 436

I'm trying to create a MVC structure and use composer to autoload everything. But I keep getting this error:

<b>Fatal error</b>: Uncaught Error: Class 'App\Core\Main' not found in /var/www/html/php-framework/index.php:20
Stack trace:
#0 {main}
thrown in <b>/var/www/html/php-framework/index.php</b> on line <b>20</b><br />

My Structure:

Php-framework
 -> src
     -> Core
         -> Main.php  
 -> vendor
 -> composer.json
 -> index.php

composer.json file

   "psr-4": {
     "App\\":"src/"
   }

Main.php file

 namespace App\Core;
 Class Main{
     public static function run() { 

index.php file

 require __DIR__ . "/vendor/autoload.php";
 
 App\Core\Main::run();

but it show me error

This is d my first question on stackoverflow

2 Answers

Yup!!

I have resolved the bug myself. I don't know how, but it's working fine.

I followed the steps below:

  1. Remove vendor folder
  2. Run composer dump-autoload -o
Related