问题
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.
来源:https://stackoverflow.com/questions/18595027/symfony2-routing-use-parameters-as-controller-or-action-name