所以我一直从我的app.php中收到此错误,并且不知道发生了什么。我正在关注有关如何在php中制作购物车的教程。我将保留代码和错误文本,也许你们有一个主意。
错误文字:
致命错误:未捕获的错误:找不到“ Cart \ App”类 C:\ xampp \ htdocs \ cart \ bootstrap \ app.php:11堆栈跟踪:#0 C:\ xampp \ htdocs \ cart \ public \ index.php(3):require()#1 {main}抛出 在第11行的C:\ xampp \ htdocs \ cart \ bootstrap \ app.php中
为节省您一些时间,错误来自$ app =新应用;
代码:
<?php
use Cart\App;
use Slim\Views\Twig;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new App;
$container = $app->getContainer();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'cart',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('MERCHANT_ID');
Braintree_Configuration::publicKey('PUBLIC_KEY');
Braintree_Configuration::privateKey('PRIVATE_KEY');
require __DIR__ . '/../app/routes.php';
$app->add(new \Cart\Middleware\ValidationErrorsMiddleware($container->get(Twig::class)));
$app->add(new \Cart\Middleware\OldInputMiddleware($container->get(Twig::class)));
作曲家:
{
"require": {
"slim/slim": "^3.0",
"slim/twig-view": "^2.4",
"php-di/slim-bridge": "^2.0",
"illuminate/database": "^5.6"
},
"autoload": {
"psr-4": {
"Cart\\": "app"
}
}
}
App.php:
<?php
namespace Cart;
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');
}
}
Container.php:
<?php
use function DI\get;
use Slim\Views\Twig;
use Cart\Basket\Basket;
use Cart\Models\Product;
use Cart\Models\Payment;
use Slim\Views\TwigExtension;
use Interop\Container\ContainerInterface;
use Cart\Support\Storage\SessionStorage;
use Cart\Support\Storage\Contracts\StorageInterface;
use Cart\Validation\Contracts\ValidatorInterface;
use Cart\Validation\Validator;
use Cart\Models\Order;
use Cart\Models\Customer;
use Cart\Models\Address;
return [
'router' => get(Slim\Router::class),
ValidatorInterface::class => function (ContainerInterface $c) {
return new Validator;
},
StorageInterface::class => function (ContainerInterface $c) {
return new SessionStorage('cart');
},
Twig::class => function (ContainerInterface $c) {
$twig = new Twig(__DIR__ . '/../resources/views', [
'cache' => false
]);
$twig->addExtension(new TwigExtension(
$c->get('router'),
$c->get('request')->getUri()
));
$twig->getEnvironment()->addGlobal('basket', $c->get(Basket::class));
return $twig;
},
Product::class => function (ContainerInterface $c) {
return new Product;
},
Order::class => function (ContainerInterface $c) {
return new Order;
},
Customer::class => function (ContainerInterface $c) {
return new Customer;
},
Address::class => function (ContainerInterface $c) {
return new Address;
},
Payment::class => function (ContainerInterface $c) {
return new Payment;
},
Basket::class => function (ContainerInterface $c) {
return new Basket(
$c->get(SessionStorage::class),
$c->get(Product::class)
);
}
];
答案 0 :(得分:0)
use
语句必须在autoload.php
导入之后
答案 1 :(得分:-1)
9个小时后,我解决了它,因为它是拼写错误的名称,而不是我写的Nmae,所以对于每个有此问题的人,请检查所有您必须正确纠正的名称和类,这是唯一的解决方法