繁体   English   中英

Symfony 3.4供应商自动接线

[英]Symfony 3.4 vendor autowire

我遇到了与symfony 3.4有关的问题。 我认为我没有正确安装symfony autowire,但找不到导致错误的原因。

我重新安装了symfony,只安装了一个附加软件包:League league/tactician-bundle

我尝试按照以下方式将其注入DefaultController的构造函数中:

/**
 * @var CommandBus
 */
private $bus;

public function __construct(CommandBus $bus)
{
    $this->bus = $bus;
}

/**
 * @Route("/", name="homepage")
 */
public function indexAction(Request $request)
{
    dump($this->bus);die;
}

我的services.yml未被修改。 当我按下控制器时,出现以下错误: Cannot autowire service "AppBundle\\Controller\\DefaultController": argument "$bus" of method "__construct()" references class "League\\Tactician\\CommandBus" but no such service exists. You should maybe alias this class to the existing "tactician.commandbus.default" service. Cannot autowire service "AppBundle\\Controller\\DefaultController": argument "$bus" of method "__construct()" references class "League\\Tactician\\CommandBus" but no such service exists. You should maybe alias this class to the existing "tactician.commandbus.default" service.

当我在我的services.yml文件中定义它,例如League\\Tactician\\CommandBus: '@tactician.commandbus.default'一切似乎都可以正常工作,但是用这种方式定义我需要的每项服务都非常不舒服。 是唯一的方法还是我想念东西?

提前致谢!

我很确定您忘了注册捆绑软件,这是我可以重现此问题的唯一方法。 转到您的AppKernel.php并添加

 
 
 
  
  new League\\Tactician\\Bundle\\TacticianBundle()
 
  

在您的$ bundles数组中。

LE我的坏消息,不是相同的错误消息。 您使用的是哪个版本的捆绑软件? 我有“ ^ 1.1”,并且工作无懈可击。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM