Reputation: 2507
I got a locales declaration in my parameters.yml
parameters:
locale: en
locales: [ en, de, fr, it, es, pt, ru, ja, zh ]
and want to reuse the locales
param in routing.yml
homepage_locale:
pattern: /{_locale}
defaults: { _controller: SiteBundle:World:index }
requirements: { _locale: %locales% }
But this obviously results in
The container parameter "locales", used in the route configuration value
"%locales%", must be a string or numeric, but it is of type array.
Is there a way to reuse this param or do I really have to write the locales as a string to satisfy this yaml/regex format, like this:
en|de|fr|it|es|pt|ru|ja|zh
Upvotes: 4
Views: 1732
Reputation: 369
In src/AppBundle/DependencyInjection/AppExtension.php
you can add in load function this code
$languages = $container->getParameter('languages');
$container->setParameter('languages_string', implode('|', $languages));
Then you will can use in your annotation
* requirements={"_locale": "%languages_string%"},
It prevent from duplicate parameters in your config file.
Upvotes: 4
Reputation: 12306
What about it:
parameters:
locale: en
locales: en|de|fr|it|es|pt|ru|ja|zh
Upvotes: 1