英文:
Is it possible to define routes.yaml defaults/requirements globally?
问题
在Symfony 6的routes.yaml中,我有以下配置:
somepage1:
path: /{_locale}/somepage1
controller: App\Controller\PageController::somepage1
defaults:
_locale: en
requirements:
_locale: en|fr|de
somepage2:
path: /{_locale}/somepage2
controller: App\Controller\PageController::somepage2
defaults:
_locale: en
requirements:
_locale: en|fr|de
由于会有很多路由,是否可能更全局地定义defaults和requirements,以便它们适用于使用_locale变量的所有URL?这样可以避免在添加新语言时为所有路由输入这些内容。
英文:
In Symfony 6 routes.yaml I have:
somepage1:
path: /{_locale}/somepage1
controller: App\Controller\PageController::somepage1
defaults:
_locale: en
requirements:
_locale: en|fr|de
somepage2:
path: /{_locale}/somepage2
controller: App\Controller\PageController::somepage2
defaults:
_locale: en
requirements:
_locale: en|fr|de
As there will be many routes, is it possible to define the defaults and requirements more globally, so that they get applied to all URLs that use the _locale variable? This is to avoid entering this for all the routes when new languages are added.
答案1
得分: 1
是的,所有内容都在这里写好了。
https://symfony.com/doc/6.2/the-fast-track/en/28-intl.html
您需要创建一个新的参数:
app.supported_locales: 'en|fr|de'
如果上述解决方案对您不起作用,那么您需要使用 RequestListener
来检查支持的区域设置。
英文:
Yes, everything is written here.
https://symfony.com/doc/6.2/the-fast-track/en/28-intl.html
You need to create a new parameter:
app.supported_locales: 'en|fr|de'
If above solution doesn't work for you, then you need to use RequestListener
to check for supported locales
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论