php – Symfony 2依赖注入Controller构造

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Symfony 2依赖注入Controller构造脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在Controller的构造中添加许多服务但没有成功.

class PErsonController extends Controller
{
    public function __construct(UtilITyService $Utils)
    {
        $this->util = $Utils;
    }

    public function indexAction()
    {
        ...
    }

}

我必须遵循的道路是什么

解决方法

正如@Cerad在 this post中提到的那样:

诀窍是将控制器定义为服务,然后使用服务ID而不是类名.

http://symfony.com/doc/current/cookbook/controller/service.html

脚本宝典总结

以上是脚本宝典为你收集整理的php – Symfony 2依赖注入Controller构造全部内容,希望文章能够帮你解决php – Symfony 2依赖注入Controller构造所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。