【发布时间】:2015-11-10 02:42:35
【问题描述】:
我继承了一个“普通”php 项目,即它没有使用框架或其他依赖项。我一直致力于整合Eloquent 和Ardent(用于自我验证模型)。
我已经使用 composer 安装了它们,一切似乎都运行良好。我有一个名为 Models 的文件夹,我使用引导类型文件加载类:
$loader = require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => '*********',
'username' => '*********',
'password' => '*********',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
// Autoload all the models
spl_autoload_register(function ($class) {
include 'models/' . $class . '.php';
});
LaravelBook\Ardent\Ardent::configureAsExternal(array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => '************',
'username' => '************',
'password' => '************',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
), 'en'); //English is the default messages language, may be left empty
但是,每当我尝试使用 Input::all() 时,都会导致以下错误:
Call to a member function all() on a non-object in /home/loadbay/public_html/beta/php-bin/vendor/illuminate/support/Facades/Facade.php on line 207
我假设这与 Facades 有关,但我不确定如何使其正常工作。有人可以帮我理解如何使用 Input::all() 吗?
更新
Facade.php 的第 207 行:
return $instance->$method();
【问题讨论】:
-
你用的是哪个 laravel 4.2/5?
-
我正在使用 Laravel 5 兼容组件。
-
如果不使用 Laravel 服务容器,您将无法使用它。输入门面正在尝试从容器中获取 $request 实例并在此调用 all() 但您的脚本中没有初始化容器。
-
我怀疑服务容器可能是造成这种情况的原因。有什么办法可以设置容器吗?我是容器概念的新手,所以我有点卡住了。
标签: php laravel laravel-5 facade