本文介绍了Symfony2 / routing /使用参数作为Controller或Action名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用给定的参数路由到控制器/操作?

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

例如:

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

我想用控制器和[action]替换给定路由的参数值。

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

IE: http://www.somedomain.com/Content/add 应调用动作 addAction

推荐答案

是否可以这样做, 。你将来会做什么,你必须重构你的代码,你的控制器/行动必须改变?您可能会断开链接和功能,以及可能丢失的搜索引擎优化,可能已经为该特定路线。

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.

这篇关于Symfony2 / routing /使用参数作为Controller或Action名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:31