简体   繁体   English

如何访问Symfony 2中的bundle实例?

[英]How to access to the bundle instance in Symfony 2?

I just dispatched my Symfony app into a few bundles. 我只是将我的Symfony应用程序分发到几个包中。

Some of them have a common comportement, so I want the bundle to implement an interface : 其中一些有一个共同的comportement,所以我希望bundle实现一个接口:

class KnFModMapBundle extends Bundle implements ModuleBase

But my question is : how can I access to the bundle instance to call implemented methods in another bundle controller ? 但我的问题是:如何访问bundle实例以调用另一个bundle控制器中的实现方法?

You should use Service Container to make some of bundle functions to be avaliable globally. 您应该使用Service Container使一些bundle功能在全局范围内可用。 Then you will can access to service from a controller via $this->get('service.name'); 然后你可以通过$this->get('service.name');从控制器访问服务$this->get('service.name');

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

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