Symfony2 default locale in routing

前端 未结 12 2286
猫巷女王i
猫巷女王i 2020-12-01 04:41

I have a problem with routing and the internationalization of my site built with Symfony2.
If I define routes in the routing.yml file, like this:

exampl         


        
12条回答
  •  误落风尘
    2020-12-01 04:59

    If someone is interested in, I succeeded to put a prefix on my routing.yml without using other bundles.

    So now, thoses URLs work :

    www.example.com/
    www.example.com//home/
    www.example.com/fr/home/
    www.example.com/en/home/
    

    Edit your app/config/routing.yml:

    ex_example:
        resource: "@ExExampleBundle/Resources/config/routing.yml"
        prefix:   /{_locale}
        requirements:
            _locale: |fr|en # put a pipe "|" first
    

    Then, in you app/config/parameters.yml, you have to set up a locale

    parameters:
        locale: en
    

    With this, people can access to your website without enter a specific locale.

提交回复
热议问题