php – Symfony 2依赖注入Controller构造
发布时间:2020-12-13 16:52:34 所属栏目:PHP教程 来源:网络整理
导读:我试图在Controller的构造中添加许多服务但没有成功. class PersonController extends Controller{ ? ?public function __construct(UtilityService $Utils) ? ?{ ? ? ? ?$this-util = $Utils; ? ?} ? ?public function indexAction() ? ?{ ? ? ? ?... ? ?}}
我试图在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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |