我有一个控制器的构造函数,我可以使用它
use Doctrine\ORM\EntityManagerInterface;
private $repository;
public function __construct(EntityManagerInterface $em)
{
$this->repository = $em->getRepository(Interview::class);
}
所有工作正常,直到我在services.yml中添加事件订阅者:
services:
AppBundle\EventListener\InterviewListener:
tags:
- { name: event_subscriber}
在此我的应用程序生成错误:
类型错误:传递给AppBundle \ Controller \ InterviewController :: __ construct()的参数1必须是Doctrine \ ORM \ EntityManagerInterface的实例,没有给出,在/ home / deymaz / Dev / interview / interview / vendor / symfony / symfony中调用第195行/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php
1 回答
您的InterviewListener服务配置(在services.yml中)将需要自动配置设置,或添加相关参数 .
如果您运行的是Symfony 3.3,启用了autowiring,并且类
implements EventSubscriberInterface
则可能不需要配置的其余部分,因为它已经自动配置 .