消息:在 Codeigniter3.1 中找不到 Class 'Illuminate\Database\Capsule\Manager'

Message: Class 'Illuminate\Database\Capsule\Manager' not found in Codeigniter3.1

我尝试使用 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();

实例化后

    $capsule = new Capsule;

您必须添加连接:

    $capsule->addConnectio([
        'driver'    =>    'mysql',
        'host'      =>    'localhost',
        'database'  =>    'databaseName',
        'username'  =>    'username',
        'password'  =>    'password',
        'charset'   =>    'UTF8',
        'collation' =>    'utf8_unicode_ci',
        'prefix'    =>    ''
    ]);

添加连接后,可以继续设置为全局,然后开机eloquent:

    $capsule->setAsGlobal();
    $capsule->bootEloquent();