gpt4 book ai didi

symfony - 传递给 Controller ​​的参数必须是 ContainerInterface 的实例,给定 appDevDebugProjectContainer 的实例

转载 作者:行者123 更新时间:2023-12-04 20:03:15 24 4
gpt4 key购买 nike

为什么我有这个错误?

Catchable Fatal Error: Argument 1 passed to Application\Sonata\ProductBundle\Controller\ProductAdminController::__construct() must be an instance of ContainerInterface, instance of appDevDebugProjectContainer given



这是我的 services.yml:
services:
product_admin_controller:
class: Application\Sonata\ProductBundle\Controller\ProductAdminController
arguments: ["@service_container"]
tags:
- { name: doctrine.event_listener, event: postLoad, connection: default }

我的 Controller :
class ProductAdminController extends Controller
{
protected $container;

public function __construct(\ContainerInterface $container)
{
$this->container = $container;
}
}

最佳答案

您必须通过“调用”选项注入(inject)容器,而不是我认为的参数:

services:
product_admin_controller:
class: Application\Sonata\ProductBundle\Controller\ProductAdminController
arguments: ["@another_service_you_need"]
tags:
- { name: doctrine.event_listener, event: postLoad, connection: default }
calls:
- [ setContainer,["@service_container"] ]

另外,不要忘记在监听器类中创建公共(public)方法“setContainer()”。

关于symfony - 传递给 Controller ​​的参数必须是 ContainerInterface 的实例,给定 appDevDebugProjectContainer 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27947055/

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