我尝试使用Illuminate配置Codeigniter3.1以使用ORM,但最后我得到了如下错误。
An uncaught Exception was encountered
Type: Error
Message: Class 'Illuminate\Database\Capsule\Manager' not found
Filename: /Users/sopheak/Documents/web/com/application/config/database.php
Line Number: 10
这是我的composer.json,
{
"name": "illuminate/database",
"description": "The Illuminate Database package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"keywords": ["laravel", "database", "sql", "orm"],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": ">=5.6.4",
"illuminate/container": "5.3.*",
"illuminate/contracts": "5.3.*",
"illuminate/contracts":"5.3.*",
"nesbot/carbon": "~1.20",
"codeigniter/framework": "3.1"
},
"autoload": {
"classmap": [
"application/core",
"application/models",
"application/libraries"
],
"psr-4": {
"Illuminate\\Database\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"suggest": {
"doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).",
"fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
"illuminate/console": "Required to use the database commands (5.4.*).",
"illuminate/events": "Required to use the observers with Eloquent (5.4.*).",
"illuminate/filesystem": "Required to use the migrations (5.4.*).",
"illuminate/pagination": "Required to paginate the result set (5.4.*).",
"illuminate/queue": "Required to fire login / logout events (5.4.*).",
"illuminate/session": "Required to use the session based guard (5.4.*).",
"league/flysystem": "Required to use the Flysystem local and FTP drivers (~1.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).",
"league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).",
"illuminate/database": "Required to use the database cache driver (5.4.*).",
"illuminate/redis": "Required to use the redis cache driver (5.4.*)."
},
"minimum-stability": "dev"
}
Applications / Config / config.php中的配置
$config['composer_autoload'] = true;
在public / Index.php上配置
require_once '../vendor/autoload.php';
将Application \ Database \ Capsule \ Manager中的Capsule称为Capsule。
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->setAsGlobal();
$capsule->setAsGlobal();
$capsule->bootEloquent();
答案 0 :(得分:1)
实例化
之后 $capsule = new Capsule;
你必须添加连接:
$capsule->addConnectio([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'databaseName',
'username' => 'username',
'password' => 'password',
'charset' => 'UTF8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
添加连接后,您可以继续将其设置为全局,然后启动雄辩:
$capsule->setAsGlobal();
$capsule->bootEloquent();