雄辩的致命错误:参数传递不正确的实例 [英] Eloquent fatal error: argument passed not the right instance

查看:153
本文介绍了雄辩的致命错误:参数传递不正确的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Slim和Eloquent在PHP中构建一个端点系统,如此处。当在本地开发者中运行它时,下面的代码失败,看起来是一个致命错误,基于什么方法期待

I'm in the process of building an endpoint system in PHP using Slim and Eloquent, as outlined here. When running it in my local dev, the code below fails with what appears to be a Fatal Error based on what the methods are expecting

// Load Eloquent
$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory();
$conn = $connFactory->make($settings);
$resolver = new \Illuminate\Database\ConnectionResolver();
$resolver->addConnection('default', $conn);
$resolver->setDefaultConnection('default');
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);

实际的错误是:

[Wed Aug 13 10:31:44 2014] PHP Catchable fatal error:  Argument 1 passed to
Illuminate\Database\Connectors\ConnectionFactory::__construct() must be an instance 
of Illuminate\Container\Container, none given, called in
/Users/outsider/application/index.php on line 22 and defined in
/Users/outsider/application/vendor/illuminate/database/Illuminate/Database/Connectors/ConnectionFactory.php on line 25

没有关于这个的文件中的很多指导。关于可能的原因的任何想法?

There's not a whole lot of guidestones in the docs about this. Any ideas on the possible cause?

推荐答案

有一个更简单的方法来使用Laravel以外的雄辩。您可以使用Capsule:

There is an easier way to use Eloquent outside Laravel. You can use Capsule:

/* Setup Eloquent. */
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;

$capsule = new Capsule;
$capsule->addConnection([
    "driver"    => "mysql",
    "host"      => "localhost",
    "database"  => "example",
    "username"  => "root",
    "password"  => "t00r",
    "charset"   => "utf8",
    "collation" => "utf8_general_ci",
    "prefix"    => ""
]);

$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->bootEloquent();

这篇关于雄辩的致命错误:参数传递不正确的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆