Symfony2 从 URL 获取路由名称 [英] Symfony2 Get route name from URL
本文介绍了Symfony2 从 URL 获取路由名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,您可以使用 app.request.attributes.get('_route')
获取当前路由名称,但无法从 url 获取?
ok you can get current route name with app.request.attributes.get('_route')
but it's not possible to get from an url ?
类似于app.request.attributes.get('/about')
?
推荐答案
您可以为此使用 Router
类/服务:
You can use the Router
class/service for this:
public function indexAction()
{
$router = $this->get('router');
$route = $router->match('/foo')['_route'];
}
这篇关于Symfony2 从 URL 获取路由名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文