我遵循phpacademys的新认证教程https://www.youtube.com/watch?v=PF2WkRCZfBg
我有一个类文件database.php:
<?php
use IlluminateDatabaseCapsuleManager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => $app->config->get('db.driver'),
'host' => $app->config->get('db.host'),
'database' => $app->config->get('db.name'),
'username' => $app->config->get('db.username'),
'password' => $app->config->get('db.password'),
'charset' => $app->config->get('db.charset'),
'collation' => $app->config->get('db.collation'),
'prefix' => $app->config->get('db.prefix')
]);
$capsule->bootEloquent();
但是它抛出了这个错误:
致命错误:在C:xampphtdocsboilerplateapp Database .php第4行中找不到"IlluminateDatabaseCapsuleManager"类
我在start.php中需要它
<?php
require 'database.php';
//############ NAMESPACING ################//
use SlimSlim; //import slim
use NoodlehausConfig;
use BoilerplateUserUser;
//#########################################//
session_cache_limiter(false);
session_start();
ini_set('display_errors','on'); //TURN OFF ON LIVE SITE
define('INC_ROOT', dirname(__DIR__)); //create local root
require INC_ROOT . '/vendor/autoload.php'; // autoload in all the dependencies in the vendor files.
$app = new Slim([
'mode' => file_get_contents(INC_ROOT . '/mode.php')
]); //assign the entire app file to a variable
$app->configureMode($app->config('mode'), function() use ($app){
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php"); //pull in the config file
});
$app->container->set('user', function(){
return new User;
});
确保您已将IlluminateDatabase
添加到您的编写器文件中,并运行composer update
然后在添加自动装弹器后放入require 'database.php';
require INC_ROOT . '/vendor/autoload.php';
// Below here
我也有同样的错误。在我的情况下,解决方案是使用下一个命令再次安装composer:
composer install
如果您正在使用docker,请确保在运行安装命令之前您在容器内。
docker-compose run <app_name> bash