2

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

Webber
  • 4,672
  • 4
  • 29
  • 38
Vickysw
  • 70
  • 10
  • Make sure that the folder name `src` is in lowercase (since your have specified lowercase `src` in the composer.json). If everything is correct, post the content of your composer.json file. – ash__939 Jul 10 '20 at 14:16
  • { "autoload": { "psr-4": { "App\\":"src/" } } } – Vickysw Jul 11 '20 at 03:11

2 Answers2

0

Check your vendor/composer/autoload_psr4.php file, you must have line like

'App\\' => array($baseDir . '/src'),

If you have not this line try composer dump-autoload (https://getcomposer.org/doc/03-cli.md#dump-autoload-dumpautoload-)

Andrey Batalov
  • 59
  • 1
  • 2
  • 6
  • Yes link is same as your suggestion but still I am not getting any luck.. `'App\\' => array($baseDir . '/src'),` – Vickysw Jul 11 '20 at 03:15
0

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
Sebastian B.
  • 2,141
  • 13
  • 21
Vickysw
  • 70
  • 10
  • You needn't to remove the `vendor` folder, just do `composer dump-autoload`. If you've removed the `vendor` folder you might be missing the `packages` installed using `composer` (If any). Run `composer install` to install them again. – ash__939 Jul 15 '20 at 10:37
  • @InvalidBot I already tried with `composer dump-autoload` But its not reflect to the code and then after tried also clear cache command but there was same error displayed... But anyway thanks for my attention and comment on it. – Vickysw Jul 16 '20 at 03:47