[英]Is possible use prefix or const in a path of the route in symfony
I tried to look how i can put a prefix in a path of route. 我试图看看如何在路由路径中添加前缀。
#routing.yml
app_news:
path: /panel/news
defaults: { _controller: NewsBundle:Default:index }
I have some routes like this, if i want change in the future the name of the path, for example 我有一些这样的路线,例如,如果将来我想更改路径名称,
/admin/news or /control/news / admin / news或/ control / news
Can i save the prefix in other config yml file and change it when i want? 我可以将前缀保存在其他config yml文件中并在需要时更改它吗?
Put all of your prefixed routes on the same routing file and then add it to your bundle routing using the resource and the prefix attribute: 将所有带前缀的路由放在同一路由文件中,然后使用资源和prefix属性将其添加到捆绑路由中:
applications:
resource: "@NewsBundle/Resources/config/routing_news.yml"
prefix: /panel
Also, if you have your routes on your controller. 另外,如果您的控制器上有路由。 You can do the same trick using the annotation attribute: 您可以使用批注属性执行相同的操作:
applications:
resource: '@NewsBundle/Controller/NewsController'
type: annotation
prefix: /panel
Syntaxis changes depending on your Symfony version, so I recommend you to visit the Symfony documentation . 语法会根据您的Symfony版本进行更改,因此我建议您访问Symfony文档 。
In this case i have some like this 在这种情况下,我有这样的
#/app/config/routing.yml
users:
resource: "@UsersBundle/Resources/config/routing.yml"
prefix: /panel/
news:
resource: "@NewsBundle/Resources/config/routing.yml"
prefix: /panel/
Now, after read the answers and see the others ways i put the prefix, i set the prefix in a var 现在,在阅读答案并查看我放置前缀的其他方式之后,我在var中设置了前缀
#/app/config/routing.yml
users:
resource: "@UsersBundle/Resources/config/routing.yml"
prefix: %panel_path%
news:
resource: "@NewsBundle/Resources/config/routing.yml"
prefix: %panel_path%
And i set the %panel_path% var value in 我在其中设置了%panel_path%var值
#/app/config/config.yml
parameters:
panel_path: /panel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.