从Symfony中的路由条件表达式访问全局参数 [英] Access global parameters from route condition expressions in Symfony
问题描述
I'm trying to access app-wide symfony parameters (defined in app/config/parameters.yml) from an expression in a route condition (documentation).
I tried my luck inserting the parameter within percentage signs and through the function "parameter" (as described for DI here), both to no avail.
下面是带有参数函数的示例:
Here is the example with the parameter function:
example_route:
path: /example/{_locale}
condition: "request.getLocale() in parameter('locales_array')"
defaults:
_controller: "AcmeExampleBundle:Example:index"
_locale: %locales_default%
但是我得到了:
However I'm getting:
语法错误-位置24附近不存在函数参数".
SyntaxError - The function "parameter" does not exist around position 24.
有没有办法从路由条件表达式中访问参数?
Is there a way to access parameters from the routing condition expressions?
推荐答案
我在 https打开了PR 2.7版本的://github.com/symfony/symfony/pull/12869 ,直到完成并交付为止,如果您的项目中需要使用UrlMatcher,则您必须使用自己的扩展版本,而您需要在其中添加容器函数提供程序,并在ExpressionLanguage#evaluate的变量"参数中注入一个容器,以便您可以访问参数和服务.
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.
您可以查看PR,以获取有关操作方法的提示,如果以后需要,我会对其进行详细介绍.
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.
这篇关于从Symfony中的路由条件表达式访问全局参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!