gpt4 book ai didi

php - Eloquent fatal error : argument passed not the right instance

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:42 25 4
gpt4 key购买 nike

我正在使用 Slim 和 Eloquent 在 PHP 中构建端点系统,如概述here .在我的本地开发人员中运行它时,下面的代码失败并出现基于方法预期的 fatal error

// 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

文档中没有很多关于此的指南。关于可能的原因有什么想法吗?

最佳答案

感谢 Manolo 指出我遗漏的内容。我需要声明一个容器并对其进行初始化:

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

关于php - Eloquent fatal error : argument passed not the right instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25289627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com