合并YAML中的可重用块(Symfony框架)

问题描述 投票:0回答:2

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

在Parser.php第290行: 第188行(“<<:*'%保险%'”附近)不存在参考“'%insurance%'”。

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时,我做错了吗?

symfony yaml config
2个回答
0
投票

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

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


0
投票

所以我再试一次,@ 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

这很好用:)也可以为你的思想覆盖一切。

© www.soinside.com 2019 - 2024. All rights reserved.