Symfony3配置TreeBuilder

时间:2017-01-18 20:23:55

标签: php yaml symfony

我在 app / config.yml

中有以下部分
bp_image:
    types:
        user_avatar:
            width: 200
            height: 200
            upload_path: '%kernel.root_dir%/../web/uploads'

在我的Bundle配置文件中我有:

$rootNode = $treeBuilder->root('bp_image');
    $rootNode
        ->fixXmlConfig('type')
        ->children()
            ->arrayNode('types')
                ->requiresAtLeastOneElement()
                ->useAttributeAsKey('name')
                ->prototype('array')
                    ->children()
                        ->variableNode('width')->end()
                        ->variableNode('height')->end()
                        ->variableNode('upload_path')->end()
                    ->end()
                ->end()
            ->end()
        ->end(); 

当我尝试处理配置时,Symfony抛出以下异常:

InvalidConfigurationException in ArrayNode.php line 317: 
Unrecognized option "user_avatar" under "bp_image"

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:0)

Resoloved。问题在于我调用解析器的方式。