Symfony2-一种获取捆绑包中所有控制器的方法吗? [英] Symfony2 - A way to get all controllers of a bundle?

查看:52
本文介绍了Symfony2-一种获取捆绑包中所有控制器的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取捆绑软件的所有控制器(和类)?包括所有父级控制器?

Is there a way to get all controllers (and the class) of a bundle ? Including all parent contollers ?

谢谢

推荐答案

最现实的方式

控制器没有文档所暗示的必需结构。无需在名称后加上 Action 作为操作方法的后缀。之所以以这种方式进行记录,是因为许多人在其路由yml中使用catch all配置,因此需要后缀来猜测端点。

A controller doesn't have a required structure as the documentation implies. An action method does not need to be suffixed with Action in the name. The reason it is documented this way is because a lot of people use the catch all configuration in their routing yml, the suffix is needed to guess the endpoints.

打印时删除路由:

print_r($this->container->get('router')->getRouteCollection()->all());

您将看到针对每条路线使用的控制器方法。
从技术上讲,这些路线不会属于任何束,因为您可以将路线指向任何类的任何方法。

You will see the controller methods used against each route. These routes technically don't 'belong' to any bundle since you can point a route at any method of any class.

但是,您可以使用列表和一些字符串魔术来告诉基于名称空间的捆绑软件。

However, you can use the list and a bit of string magic to tell the bundle based on the namespace.

请记住, _controller web_profiler.controller.profiler:infoAction 表示该方法属于通过依赖项注入实例化的服务。

Bare in mind that a _controller like web_profiler.controller.profiler:infoAction means the method belongs to a service instantiated via dependency injection.

这篇关于Symfony2-一种获取捆绑包中所有控制器的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆