[英]Fatal error: Uncaught Error: Class 'maimana\App' not found — slim3
i was following alex's how to build a shopping cart lesson and everything's working fine. 我一直在遵循Alex的方法来构建购物车课程,并且一切正常。 but then i dont know what im doing wrong so i get this error :
但是后来我不知道我在做什么错,所以我得到了这个错误:
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 : 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 : 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');
}
}
anyone know what's going on? 有人知道发生了什么吗?
Rename the Myapp
directory to maimana
(note case) and then update your composer.json
to autoload the maimana
namespace. 重命名
Myapp
目录maimana
(注意大小写),然后更新您的composer.json
自动加载的maimana
命名空间。
ie ensure that your composer.json has: 即确保您的composer.json具有:
"autoload": {
"psr-4": {
"maimana\\": "maimana/"
}
}
This assumes that the maimana
directoryis in the root of your project where the composer.json
file is. 假设
maimana
目录位于composer.json
文件所在项目的根目录中。 Once you have changed composer.json
, you need to run composer dumpautoload
for the changes to take effect. 更改
composer.json
,需要运行composer dumpautoload
才能使更改生效。
This is required because there is a one to one mapping between directory name that the PHP file is in and the namespace for the class in that PHP file. 这是必需的,因为在PHP文件所在的目录名称与该PHP文件中类的名称空间之间存在一对一的映射。 As the namespace in your
App.php
is maimana
, the directory needs to be maimana
. 由于
App.php
的名称空间为maimana
,因此目录必须为maimana
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.