I have defended a few routes under "config/routes/modul.yaml" (Symfony 4). I need for every rest route county and language.
# Modul route definition
sym_modul1:
path: /{country}/{language}/modul/test1
controller: App\Controller\ModulController::test1
requirements:
language: en|fr|de|es|cs|it
country: GB|FR|DE|ES|CS|IT
sym_modul2:
path: /{country}/{language}/modul/test2
controller: App\Controller\ModulController::test2
requirements:
language: en|fr|de|es|cs|it
country: GB|FR|DE|ES|CS|IT
sym_modul2:
path: /{country}/{language}/modul/test3
controller: App\Controller\ModulController::test3
requirements:
language: en|fr|de|es|cs|it
country: GB|FR|DE|ES|CS|IT
So far so good. But I do not like the idea (later when there are many routs) to add a new country or language in each file and each route.
I have seen in the symfony demo, it possible to define the {_locale} wildcart gobal for routes. In "config/routes.yaml" it look like this
homepage:
path: /{_locale}
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction
requirements:
_locale: '%app_locales%'
defaults:
template: default/homepage.html.twig
_locale: '%locale%'
But I think this will only work with {_locale}
because is it _locale
is set in the internal User Object. Is there a better way in Symfony to do this?