[英]Symfony 3.4 vendor autowire
I've got a problem with symfony 3.4 I'm stuck with. 我遇到了与symfony 3.4有关的问题。 I think i'm not getting symfony autowire right, but I can't find what's causing the error.
我认为我没有正确安装symfony autowire,但找不到导致错误的原因。
I have a fresh installation of symfony with only one addtional package installed: league/tactician-bundle
我重新安装了symfony,只安装了一个附加软件包:League
league/tactician-bundle
I try to inject it in constructor of DefaultController in the folowing way: 我尝试按照以下方式将其注入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;
}
My services.yml is untouched. 我的services.yml未被修改。 When I hit the controller I get following error:
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.
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.
When I define it in my services.yml like this League\\Tactician\\CommandBus: '@tactician.commandbus.default'
everything seems to work, but this is very uncomfortable to define every service I need in this way. 当我在我的services.yml文件中定义它,例如
League\\Tactician\\CommandBus: '@tactician.commandbus.default'
一切似乎都可以正常工作,但是用这种方式定义我需要的每项服务都非常不舒服。 Is it the only way or am I missing somehting? 是唯一的方法还是我想念东西?
Thanks in advance! 提前致谢!
I'm pretty sure you forgot to register the bundle, that's the only way i could repro the issue.
我很确定您忘了注册捆绑软件,这是我可以重现此问题的唯一方法。
Go to your AppKernel.php and add
转到您的AppKernel.php并添加
new League\\Tactician\\Bundle\\TacticianBundle()
in your $bundles array.
在您的$ bundles数组中。
LE my bad, not the same error message. LE我的坏消息,不是相同的错误消息。 What version of the bundle are you using?
您使用的是哪个版本的捆绑软件? I've got "^1.1" and worked flawless.
我有“ ^ 1.1”,并且工作无懈可击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.