Symfony 4 在容器中添加服务
Symfony 4 add service in container
我在 symfony 4 中使用 csa_guzzle_bundle,目前我在 csa_guzzle.yaml 中有 2 个客户端,但可能还有更多未来。
所以,我想用容器 $this->get("csa_guzzle.clients.".$client");
动态调用 csa_guzzle_client 它在 symfony 3 中工作但在 symfony 4 中不工作,因为自动装配。
我的问题是为什么要在 container_bag 中添加服务以便与 $this->get('alias');
一起使用?
感谢帮助
感谢 Thomas Lefetz,如果您使用任何服务 no public with methode ->get('')。从 Symfony\Bundle\FrameworkBundle\Controller\Controller 继承你的控制器,没有 AbstractController。
我在 symfony 4 中使用 csa_guzzle_bundle,目前我在 csa_guzzle.yaml 中有 2 个客户端,但可能还有更多未来。
所以,我想用容器 $this->get("csa_guzzle.clients.".$client");
动态调用 csa_guzzle_client 它在 symfony 3 中工作但在 symfony 4 中不工作,因为自动装配。
我的问题是为什么要在 container_bag 中添加服务以便与 $this->get('alias');
一起使用?
感谢帮助
感谢 Thomas Lefetz,如果您使用任何服务 no public with methode ->get('')。从 Symfony\Bundle\FrameworkBundle\Controller\Controller 继承你的控制器,没有 AbstractController。