Symfony配置解析

时间:2017-03-10 08:35:21

标签: symfony

我的config.yml上有以下配置

ci_api:
    file:
        purposes:
            attachment:

我的配置类看起来像这样:

    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('ci_api');

    $rootNode
        ->children()
            ->arrayNode('file')
                ->children()
                    ->arrayNode('purposes')
                        ->children()

                        ->end()
                    ->end()
                ->end()
            ->end()
        ->end(); //children

    return $treeBuilder;

当我试图运行它时会收到错误消息:

  

“ci_api.file.purposes”下无法识别的选项“附件”

请注意,根据目的,可能会有无限数量的儿童。

感谢。

1 个答案:

答案 0 :(得分:1)

只需将原型定义作为数组添加到最后一个元素定义中,如下所示:

$rootNode
    ->children()
        ->arrayNode('file')
            ->children()
                ->arrayNode('purposes')
                    ->prototype('array')  // Add this line
                    ->children()

                    ->end()
                ->end()
            ->end()
        ->end()
    ->end(); //children