如何为 Symfony2 中的所有控制器添加一些路由前缀? [英] How can I add some route prefix to all controllers in Symfony2?
本文介绍了如何为 Symfony2 中的所有控制器添加一些路由前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用注解来定义控制器中的路由,我有 15 个控制器.全部由 /path1
, /path2
执行.
I am using annotations to define routes in controllers and I have 15 controllers. All are executed by /path1
, /path2
.
有没有办法在所有这些控制器中,我可以通过 /admin/path1
和 /admin/path2
访问它们?
Is there any way that in all those controller , I can access them via /admin/path1
and /admin/path2
?
我不想通过更改每个文件来输入.
I don't want to enter that by changing each file.
我可以从一个位置执行此操作吗?我的意思是整个包应该通过 /admin
然后它们各自的路径打开.
Can I do that from a single location? I mean the whole bundle should open via /admin
and then their respective paths.
推荐答案
试试这个
# app/config/routing.yml
acme_hello:
resource: "@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /admin
或者如果使用注释
resource: "@AcmeHelloBundle/Controller"
type: annotation
prefix: /admin
这篇关于如何为 Symfony2 中的所有控制器添加一些路由前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文