Locale in route prefix

走远了吗. 提交于 2020-01-24 20:07:05

问题


I'm trying to prefix all routes within single controller with _locale but so far I haven't had any success:

/**
 * @Route("/{_locale}/events", requirements={"_locale": "en"})
 * @Route("/{_locale}/evenements", requirements={"_locale": "fr"})
 */
class SomeController extends Controller{

    /**
     * @Route("/", name="events")
     */
    public function indexAction(){
       ... 
    }

    ...
}

route:debug does not even list URLs prefixed by second @Route. I tried removing _locale slug altogether but still, route could not be found.

Am I missing something here? Is it even possible to have multiple prefixes?

Any help would be greatly appreciated...


回答1:


Firstly, do you have defined in your file Ressources/config/routing.yml that you're using annotation for this controller ?

#file Ressources/config/routing.yml
blog:
    resource: "@YourBundle/Controller"
    type:     annotation

Also you can define your routes as :

/**
 * @Route("/en/events", defaults={"_locale": "en"})
 * @Route("/fr/evenements", defaults={"_locale": "fr"})
 */


来源:https://stackoverflow.com/questions/16254152/locale-in-route-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!