[英]Symfony global and specific prefix controller action
I have in my file routing.yml configured a prexif for all my route like : 我在文件routing.yml中为所有路由配置了prexif,例如:
app:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: en|fr|es
With this, for all my controllers I have a prefix _locale
like : /en/buy
, /en/home
... 有了这个,对于我所有的控制器,我都有一个前缀
_locale
例如: /en/buy
, /en/home
...
I have another controller AjaxController
and i don't need to use this prefix, but another one : ajax
. 我有另一个控制器
AjaxController
,我不需要使用这个前缀,但是另一个是: ajax
。
How can I keep my global prefix _locale
for all my controllers and use another prefix for just my AjaxController ? 我如何为我的所有控制器保留全局前缀
_locale
,而仅对我的AjaxController使用另一个前缀?
Thanks ! 谢谢 !
In symfony routing, the last rule declared is the one which is used by the router. 在symfony路由中,最后声明的规则是路由器使用的规则。 I didn't test it but I guess something like that should be working :
我没有测试它,但我猜类似的东西应该可以工作:
app:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: en|fr|es
app_ajax:
resource: "@AppBundle/Controller/AjaxController.php"
type: annotation
prefix: /ajax
Once again, I didn't try it ! 再一次,我没有尝试! But i'm pretty sure it's gonna work.
但是我很确定它会起作用。 I don't really like these kind of practices in general because it relies upon the router's behaviour, that could be changing through versions…
我总体上不太喜欢这种做法,因为它取决于路由器的行为,可能会随着版本的变化而变化……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.