1
votes

Is there are way to get current matched route configuration parameters in a controller (in Symfony2)?

Basically what I need to know is:

I have my route.yml file (for example):

my_app_route:
  pattern: /app/route
  defaults: { _controller: "MyAppBundle:Default:index", _format: json }
  requirements: { _method: post|put }

I want to be able to get these parameter values in controller. Not request parameters, but configuration parameter of a matching route (for a current Request). When I have a request that matching this route, I want to get _method (post|put) of this matching request.

Can anyone help me with this? Thanks.

1
Do you need, what _method is configured, or with what method the request was made?Emii Khaos
That's the thing, I need to get configured method(s).user1863635

1 Answers

0
votes

Maybe \Symfony\Component\Routing\Router::match can return what you need. Within a controller

$routeParams = $this->get('router')->match('/');

should return an array of parameters for the route matching the homepage.