Symfony2 default locale in routing

前端 未结 12 2235
猫巷女王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 05:04

    You can define multiple patterns like this:

    example_default:
      pattern:   /example
      defaults:  { _controller: ExampleBundle:Example:index, _locale: fr }
    
    example:
      pattern:   /{_locale}/example
      defaults:  { _controller: ExampleBundle:Example:index}
      requirements:
          _locale:  fr|en
    

    You should be able to achieve the same sort of thing with annotations:

    /**
     * @Route("/example", defaults={"_locale"="fr"})
     * @Route("/{_locale}/example", requirements={"_locale" = "fr|en"})
     */
    

    Hope that helps!

提交回复
热议问题