Symfony2 / routing / use parameters as Controller or Action name

帅比萌擦擦* 提交于 2020-01-03 19:09:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!