Symfony 2:如何通过路由名称获取默认路由? [英] Symfony 2: How to get route defaults by route name?

查看:94
本文介绍了Symfony 2:如何通过路由名称获取默认路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过名称检索有关某条路线的信息,或获取所有路线的列表?

Is it possible to retrieve info about a certain route by its name, or get a list of all routes?

我需要能够获取<$ 默认值中的c $ c> _controller 值适用于任何路由,不仅限于当前路由。

I need to be able to fetch the _controller value in defaults for any route, not only the current.

这可能吗?

PS:我发现我可以找到使用YAML的路线,但是重新解析似乎不必要而且繁琐。

P.S.: I found I could get the path to the routes YAML being used, but reparsing it seems unnecessary and heavy.

推荐答案

我真的很擅长回答自己的问题。

I am really good at answering my own questions..

路由在路由器上使用 getRouteCollection() $ this-> get('router')-> getRouteCollection()在控制器中),然后获取RouteCollection实例,在该实例上可以 all() get($ name)

To get routes use getRouteCollection() on the router ($this -> get('router') -> getRouteCollection() inside a controller), then you get RouteCollection instance on which you can all() or get($name).

这篇关于Symfony 2:如何通过路由名称获取默认路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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