3

在 symfony2 中,我使用了以下配置 yaml:

// config.yml
parameters:
  something: 
    content: 
      price:  2.30
      mainText: 'Some text here.'
      redText:  'This is a text here plus price: ' %price%

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

4

3 回答 3

7

这是你可以做到的

parameters:
    something.content.price: 2.30
    something:
        content:
            mainText: 'Some text here.'
            redText:  'This is a text here plus price: %something.content.price%'

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

这意味着您将只能在 DI 配置中直接访问这 2 个。

于 2012-07-08T17:20:18.727 回答
1

一样的答案,不一样的帖子

有点晚了,但这是您正在寻找的解决方案:P

// parameters.yml
parameters:
    something: 
    content: 
        price:  2.30
        mainText: 'Some text here.'
        redText:  'This is a text here plus price: '

使用数组中定义的价格的方法类似于:

//config.yml 
twig:
    globals:
        fee: content['price']

说明
当您将参数文件导入 config.yml 文件时,您可以自动访问其中定义的所有变量。请记住,当您使用您定义的结构时。

您正在定义一个名为content的键值对数组,其中包含许多键值对,并且引用它们的方式如上所述。

希望这对那些可能正在寻找它的人有用!:)

于 2017-07-13T23:43:51.633 回答
-2

也许%something.content.price%

于 2012-07-07T00:04:13.363 回答