【发布时间】:2015-10-12 04:47:38
【问题描述】:
我关注phpacademys新的认证教程https://www.youtube.com/watch?v=PF2WkRCZfBg
我有一个类文件database.php:
<?php
use Illuminate\Database\Capsule\Manager 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();
但是它抛出了这个错误:
致命错误:第 4 行的 C:\xampp\htdocs\boilerplate\app\database.php 中找不到类“Illuminate\Database\Capsule\Manager”
我在 start.php 中需要它
<?php
require 'database.php';
//############ NAMESPACING ################//
use Slim\Slim; //import slim
use Noodlehaus\Config;
use Boilerplate\User\User;
//#########################################//
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;
});
【问题讨论】:
-
你是在使用 composer 引入 Illuminate\Database 吗?
-
是的,这是我的 json 文件 { "autoload": { "psr-4" : { "Boilerplate\\" : "app/Boilerplate" } }, "require": { "slim /slim”:“~2.0”,“slim/views”:“0.1.*”,“phpmailer/phpmailer”:“~5.2”,“hassankhan/config”:“0.8.*”,“twig/twig”: “~1.0”、“照亮/数据库”:“~5.0”、“ircmaxell/random-lib”:“~1.1”}
标签: php laravel eloquent composer-php vendor