my parameters.yml 文件有:
parameters:
title:
subtitle: value
我想将value
传递给 config.yml 中的服务
my_service:
class: the_class
arguments: [ %title.subtitle%] //didn't work
arguments: [ %title['subtitle']%] //didn't work
我该怎么做?
> Symfony2不支持使用%
表示法读取参数数组上的单个元素。你正在做的事情不可能开箱即用。
执行此操作的唯一方法是创建自己的Symfony'Component'DependencyInjection'ParameterBag'ParameterBag
,以支持获取数组项。
%
表示法不起作用,但可以通过以下方式完成:
my_service:
class: the_class
arguments: ["@=container.getParameter('title')['subtitle']"]
它至少适用于symfony 2.7.3
有关表达式语言的更多信息,请参阅说明书:http://symfony.com/doc/current/book/service_container.html#using-the-expression-language