我想为我自己的bundle创建一个这样的配置:
my_filters:
filter_type_a:
- 'MyBundle'My'ClassA
- 'MyBundle'My'ClassA2
filter_type_b:
- 'MyBundle'My'ClassB
my_filters
应该是一个变长数组,my_filters.filter_type_a
也应该是一个变长数组。
我试着
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_bundle');
$rootNode
->children()
->arrayNode('my_filters')
->prototype('array')
->prototype('array')
->children()
->scalarNode('my_filters')->end()
->end()
->end()
->end()
->end()
->end()
,但我得到以下错误:Invalid type for path "my_bundle.my_filters.filter_type_a.0". Expected array, but got string
.
下面是我设置配置的地方:
class MyBundleExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$this->loadServices($container);
$this->loadConfig($configs, $container);
}
private function loadConfig(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('my_bundle.my_filters', $config['my_filters']);
}
private function loadServices(ContainerBuilder $container)
{
$loader = new Loader'YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
我看不出我的错误,有人能告诉我吗? 匹配配置
my_bundle:
my_filters:
filter_type_a:
- 'MyBundle'My'ClassA
- 'MyBundle'My'ClassA2
filter_type_b:
- 'MyBundle'My'ClassB
你需要配置树构建器中的下一个代码:
$rootNode = $treeBuilder->root('my_bundle');
$rootNode
->children()
->arrayNode('my_filters')
->prototype('array')
->prototype('scalar')->end()
->end()
->end()
->end()