我想創建一個配置自己的套件是這樣的:創建symfony的配置樹構建多維數組
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');
}
}
我看不到我的錯,誰能告訴我?
你是什麼'rootNode'?更改您的一個示例以遵守對方。現在你已經定義了'filter_expressions',但是提供了'my_filters'或'filter_type_a'。目前還不清楚。 –
對不起,忘了。我已將根節點添加到示例中。 – jagemue
我認爲你的命名錯誤。你有一個名字聲明兩個不同的節點'my_filters' –