【问题标题】:Merging reusable block in YAML (Symfony framework)在 YAML 中合并可重用块(Symfony 框架)
【发布时间】:2019-04-11 20:11:08
【问题描述】:

在 Symfony 中,我尝试将 YAML 块从 parameters.yml 合并到 config.yml。我的问题是如何在 Symfony 3.4 中存储一些配置,然后插入到我的配置文件中。现在我得到一个错误:

在 Parser.php 第 290 行:
参考“'%insurance%'”在第 188 行不存在(靠近“

parameters.yml

parameters:
    Insurance: &insurance
    list:
        title: '<strong>Ubezpieczenia</strong>'
        sort: ['sequence', 'ASC']
        fields:
            - { property: 'sequence', label: 'Kolejność'}
            - { property: 'title', label: 'Tytuł'}
            - { property: 'description', label: 'Opis'}
        form:
            fields:
                - { property: 'title', type: 'text', label: 'Tytuł'}
                - { property: 'description', type: 'ckeditor', label: 'Opis',
                    type_options: { config_name: 'simple_config' }}
                - { property: 'sequence', type: 'integer', label: 'Kolejność'}

config.yml

imports:
- { resource: parameters.yml }
easy_admin:
    [...]
    entities:
        [...]
        MotorInsurance:
            class: AppBundle\Entity\MotorInsurance
            label: menu.motorInsurance
            <<: *'%insurance%'

[...] 有不相关的配置

我在调用Inusrance 阻止时是否做错了什么?

【问题讨论】:

  • 尝试在 config.yml 文件中将 &lt;&lt;: *'%insurance%' 更改为 &lt;&lt;: *insurance(引号和百分号已删除)。
  • 我以前试过这个,但没用。我认为@xabbuh 是对的,但他的解决方案在 Symfony 中不起作用,因为它解析 config.yml 仅用于扩展

标签: symfony yaml config


【解决方案1】:

这不起作用。不同的文件是独立解析的,因此您不能在另一个 YAML 文件中重用一个 YAML 文件中定义的引用。

解决方案是将所有需要的配置放在同一个文件中。

【讨论】:

    【解决方案2】:

    所以我再试一次,@xabbuh 是对的。我忘记了我的config.yml 中也有参数块。我的文件现在看起来像这样:

    parameters:
        locale: pl
        Insurance: &insurance
            list:
                title: '<strong>Ubezpieczenia</strong>'
                sort: ['sequence', 'ASC']
                fields:
                    - { property: 'sequence', label: 'Kolejność'}
                    - { property: 'title', label: 'Tytuł'}
                    - { property: 'description', label: 'Opis'}
            form:
                fields:
                    - { property: 'title', type: 'text', label: 'Tytuł'}
                    - { property: 'description', type: 'ckeditor', label: 'Opis',
                        type_options: { config_name: 'simple_config' }}
                    - { property: 'sequence', type: 'integer', label: 'Kolejność'}
    easy_admin:
    [...]
    entities:
        [...]
        MotorInsurance:
            class: AppBundle\Entity\MotorInsurance
            label: menu.motorInsurance
            <<: *insurance
    

    这很好用 :) 也可以为您的思想覆盖所有内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-07
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2021-10-03
      相关资源
      最近更新 更多