我正在尝试为我的捆绑包使用自定义配置
#app/config.yml
config.yml
my_app:
level1:
level2:
- "first data"
- "second data"
如何将这些信息作为控制器或服务
#My/AppBundle/DependencyInjection/Configuration.php
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_app');
$rootNode
->children()
->arrayNode('level1')
->children()
->arrayNode('level2')->end()
->end()
->end()
->end()
;
此代码生成以下错误:
InvalidConfigurationException in ArrayNode.php line 317: Unrecognized options "0, 1" under "my_app.level1.level2"
怎么能这样做?
答案 0 :(得分:2)
我认为你应该这样做:
->children()
->arrayNode('level2')
->prototype('scalar')->end()
->end()
如果您需要更多帮助,请查看here以获取更多信息