我的 parameters.yml
中有一个区域设置声明
parameters:
locale: en
locales: [ en, de, fr, it, es, pt, ru, ja, zh ]
并且想要重用 routing.yml
中的 locales
参数
homepage_locale:
pattern: /{_locale}
defaults: { _controller: SiteBundle:World:index }
requirements: { _locale: %locales% }
但这显然会导致
The container parameter "locales", used in the route configuration value
"%locales%", must be a string or numeric, but it is of type array.
有没有办法重用此参数,或者我真的必须将语言环境编写为字符串才能满足此 yaml/regex 格式,如下所示:
en|de|fr|it|es|pt|ru|ja|zh
最佳答案
在 src/AppBundle/DependencyInjection/AppExtension.php
您可以在加载函数中添加此代码
$languages = $container->getParameter('languages');
$container->setParameter('languages_string', implode('|', $languages));
然后您就可以在注释中使用
* requirements={"_locale": "%languages_string%"},
它可以防止配置文件中出现重复的参数。
关于symfony - 在routing.yml中使用parameters.yml中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21462858/