Laravel 4找不到Class DB

时间:2013-03-25 03:10:10

标签: php laravel laravel-4

问题:我正在尝试为某些文件(app/workers的php-resque工作者)引导L4框架使用,但工作人员似乎无法找到该类使用DB的行上的DB::table('tablename')...composer dumpautoload无效。

我使用的bootstrap是否未加载DB类?它似乎装载了工人阶级。

L4引导失败

<?php

// Bootstrap the laravel environment for our resque workers.
require __DIR__.'/bootstrap/autoload.php';

错误

PHP Fatal error:  Class 'DB' not found in /var/www/dev/app/libraries/test.php on line 50

composer.json

{
    "require": {
        "laravel/framework": "4.0.*",
        "chrisboulton/php-resque": "@stable"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/libraries",
            "app/workers"
        ]
    },
    "scripts": {
        "post-update-cmd": "php artisan optimize"
    },
    "minimum-stability": "dev"
}

1 个答案:

答案 0 :(得分:0)

您可以尝试:

1)加载位于vendor/autoload.php的Composer自动加载文件(您实际上正在调用laravel文件)

2)复制public/index.php文件中test.php文件中的来电,具体为:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
$app->run();
$app->shutdown();

编辑:经过进一步检查后,您可以尝试使用裸机:

<?php
require '../vendor/autoload.php';
use Illuminate\Support\Facades\DB as DB;
// Test the DB Instance
$dbInstance = new DB;
var_dump ($dbInstance);

将输出

object(Illuminate\Support\Facades\DB)[2]