我有DI的问题,这对我来说是新的。我想在我的Project类中将Container作为DI,但是我收到了一个错误:
textChanged
我创建了一个类Project:
myQLineEdit.textChanged.connect(lambda text: myQLabel.setStyleSheet(
"QLabel { color: %s}" % ('green' if text else 'red')))
这是我的DIC配置:
Argument 1 passed to Project::__construct() must be an instance of Slim\Container, none given
这里我的代码index.php运行代码
use Slim\Container;
class Project {
protected $ci;
public function __construct(Container $ci) {
$this->ci = $ci;
}
}
我不知道我失败的地方,我甚至尝试使用slim-brige,但我得到了相同的结果。我也尝试给一个字符串而不是容器,我仍然得到null
答案 0 :(得分:0)
传递给Project :: __ construct()的参数1必须是Slim \ Container的一个实例,没有给出
嗯,确实没有给构造函数赋予参数:
$app->get('/project/{id}', function (Request $request, Response $response) {
$project = new Project(); // You should pass container instance here, but you don't
return $response;
});
由于您已在容器中注册了Project
类,因此可以从容器中获取实例:
$app->get('/project/{id}', function (Request $request, Response $response) {
$project = $this->container->get('Project'); // Get Project instance from the container, you have already registered it
return $response;
});