Access global parameters from route condition expressions in Symfony

混江龙づ霸主 提交于 2019-12-04 12:31:25

I opened a PR at https://github.com/symfony/symfony/pull/12869 for 2.7 version, until it's done and shipped you will have to use your own extended version if UrlMatcher in your project in which you'll need to add container functions provider and also inject a container in "variables" argument of ExpressionLanguage#evaluate so that you'll be able to access parameters and services.

You can look at PR to get a hint how to do it, I'll write about it more in detail if you need later.

You are lucky (and I a bit late), I'm accessing to Symfony parameters from an expression just using the syntax %variable%.

Here are your example, tested in Symfony 3:

example_route:
    path:     /example/{_locale}
    condition: "request.getLocale() in ['%locales_array%']"
    defaults: 
        _controller: "AcmeExampleBundle:Example:index"
        _locale: %locales_default%
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!