Symfony2 / routing / use parameters as Controller

2019-07-07 01:37发布

问题:

Is it possible to route to a controller/action using given parameters ?

For example :

my_custom_route:
    pattern: /{controller}/{action}
    defaults: { _controller: AcmeDemoBundle:[controller]:[action] }

I would like [controller] and [action] to be replaced by given route's parameters values.

I.E : http://www.somedomain.com/Content/add should call action "addAction" of controller "ContentController" in bundle "AcmeDemoBundle"

回答1:

Yes you can do so however it is not recommended. What would you do in future of you had to refactor your code and your controller / action had to change? You may break links and functionality along with possibly losing search engine optimization that may have been done for that particular route.