Symfony2:引用字符串或config yaml中的数组

Tro*_*ike 3 yaml symfony

在symfony2中,我使用下面的配置yaml:

// config.yml
parameters:
  something: 
    content: 
      price:  2.30
      mainText: 'Some text here.'
      redText:  'This is a text here plus price: ' %price%
Run Code Online (Sandbox Code Playgroud)

%price%是错误的并且给我一个错误,但系统告诉它一个数组,那么如何指向['content'] [price]的东西?

Adr*_*ult 7

这是你如何做到的

parameters:
    something.content.price: 2.30
    something:
        content:
            mainText: 'Some text here.'
            redText:  'This is a text here plus price: %something.content.price%'
Run Code Online (Sandbox Code Playgroud)

这里我们只有2个参数,something.content.price包含一个浮点数,并且something包含一个数组.

这意味着您只能在DI配置中直接访问那些2.