有没有办法在控制器中获取当前匹配的路由配置参数(在Symfony2中)?
基本上我需要知道的是:
我有我的route.yml文件(例如):
my_app_route:
pattern: /app/route
defaults: { _controller: "MyAppBundle:Default:index", _format: json }
requirements: { _method: post|put }我希望能够在控制器中获得这些参数值。不是请求参数,而是匹配路由的配置参数(当前请求)。当我有一个匹配这个路由的请求时,我想获取这个匹配请求的_method (post|put)。
有人能帮我吗?谢谢。
发布于 2013-05-07 22:01:00
也许\Symfony\Component\Routing\Router::match可以返回您需要的内容。在控制器中
$routeParams = $this->get('router')->match('/');应返回与主页匹配的路由的参数数组。
https://stackoverflow.com/questions/16407011
复制相似问题