我希望创建一个自己的捆绑包配置,就像这样:
```html
我尝试过了。
我看不出我的错误,有人可以告诉我吗?
```html
我想创建一个自己的捆绑包配置,就像这样:
```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()
但是我遇到了以下错误:"my_bundle.my_filters.filter_type_a.0"的路径类型无效。期望数组,但得到了字符串
。
这是我设置配置信息的地方:
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');
}
}
我看不出我的错误,有人可以告诉我吗?
rootNode
是什么?更改其中一个示例以使它们相互兼容。现在你已经定义了filter_expressions
,但是提供了my_filters
或filter_type_a
,这是不清楚的。 - Michael Sivolobovmy_filters
声明了两个不同的节点。 - Michael Sivolobov