我的parameters.yml文件有:
parameters:
title:
subtitle: value
Run Code Online (Sandbox Code Playgroud)
我想传递value给config.yml中的服务
my_service:
class: the_class
arguments: [ %title.subtitle%] //didn't work
arguments: [ %title['subtitle']%] //didn't work
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
And*_*ore 16
Symfony2不支持使用%表示法读取参数数组上的各个元素.你开始做的事情不可能开箱即用.
唯一的方法是创建自己的Symfony\Component\DependencyInjection\ParameterBag\ParameterBag,以支持获取数组项.
use*_*408 14
该%符号不工作,但它可以完成以下方式:
my_service:
class: the_class
arguments: ["@=container.getParameter('title')['subtitle']"]
Run Code Online (Sandbox Code Playgroud)
它至少适用于symfony 2.7.3
有关表达式语言的更多信息可以在食谱中找到:http: //symfony.com/doc/current/book/service_container.html#using-the-expression-language