Fatal error: Uncaught Error: Class 'maimana\App' not found -- slim3

Fatal error: Uncaught Error: Class 'maimana\App' not found -- slim3

我一直在关注 alex 的 how to build a shopping cart lesson,一切正常。但后来我不知道我做错了什么所以我得到这个错误:

Fatal error: Uncaught Error: Class 'maimana\App' not found in /Applications/MAMP/htdocs/maimana/bootstrap/app.php:13 Stack trace: #0 /Applications/MAMP/htdocs/maimana/public/index.php(3): require() #1 {main} thrown in /Applications/MAMP/htdocs/maimana/bootstrap/app.php on line 13

bootsrap/app.php :

<?php

use Respect\Validation\Validator as v;
 use maimana\App as MyApp;
 use Slim\Views\Twig;
 use Illuminate\Database\Capsule\Manager as Capsule;


 session_start();

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

 $app = new MyApp;

 $container = $app->getContainer();


 $capsule = new Capsule;

 $capsule->addConnection([
   'driver' => 'mysql',
   'host' => 'localhost',
   'database' => 'maimana',
   'username' => 'rdp46',
   'password' => 'littlelion4696',
   'charset' => 'utf8',
   'collation' => 'utf8_unicode_ci',
   'prefix' => ''
 ]);
 $capsule->setAsGlobal();
 $capsule->bootEloquent();

 require __DIR__ . '/../app/routes.php';

Myapp/App.php :

   namespace maimana;

 use DI\ContainerBuilder;
 use DI\Bridge\Slim\App as DiBridge;

 class App extends DiBridge{
   protected function configureContainer(ContainerBuilder $builder)
   {
     $builder->addDefinitions([
       'settings.displayErrorDetails' => true,
     ]);

     $builder->addDefinitions(__DIR__ . '/container.php');
   }     
 }

有人知道发生了什么事吗?

Myapp 目录重命名为 maimana(注意大小写),然后更新您的 composer.json 以自动加载 maimana 命名空间。

即确保您的 composer.json 具有:

"autoload": {
    "psr-4": {
        "maimana\": "maimana/"
     }
}

这假定 maimana 目录位于 composer.json 文件所在的项目的根目录中。更改 composer.json 后,您需要 运行 composer dumpautoload 才能使更改生效。

这是必需的,因为 PHP 文件所在的目录名称与 PHP 文件中 class 的命名空间之间存在一对一的映射。由于 App.php 中的命名空间是 maimana,目录需要是 maimana.