How to add an array with values in Symfony2 configuration?

前端 未结 2 1947
清歌不尽
清歌不尽 2021-02-13 01:42

I would like to add a simple list of values in a configuration files (config.yml). For example :

my_bundle:
    columns: [\"col1\", \"col2\"]

W

2条回答
  •  伪装坚强ぢ
    2021-02-13 02:15

    I think you're missing that YaML is not a markup language, it's not even a langauge as such (It's a data serialization standard), so it doesn't know of any language constructs, like arrays. Its main "tool" to express grouping and relations between bits of data is whitespace, colons and dashes.
    From the symfony documentation page of the YaML format:

    my_bundle:
        columns: 
            - col1
            - col2
    

    As I gather from this section:

    A YAML file is rarely used to describe a simple scalar. Most of the time, it describes a collection. A collection can be a sequence or a mapping of elements. Both sequences and mappings are converted to PHP arrays.

    Sequences use a dash followed by a space:

    - PHP

    - Perl

    - Python

    The previous YAML file is equivalent to the following PHP code:

    array('PHP', 'Perl', 'Python');
    

提交回复
热议问题