【发布时间】:2014-05-04 16:27:10
【问题描述】:
我在我的项目中创建了一个新包,并按照how to expose the configuration 上的说明进行操作。
这部分工作正常,但是当我尝试在 bundle 配置中添加一个新的 yaml 文件(以我的 bundle 命名,以便我可能在其他 bundle config 文件夹中创建类似的命名文件并将它们合并)时,使用相同的标签并将其添加到扩展类中以进行加载我收到错误:
InvalidArgumentException: There is no extension able to load the configuration for "foo_bar_notify" (in /path/to/symfony/src/Foo/Bar/NotifyBundle/DependencyInjection/../Resources/config/notify.yml). Looked for namespace "foo_bar_notify", found none
谁能指出我错过了什么(或做错了什么)。
代码 sn-ps;
配置类
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('foo_bar_notify');
$rootNode
->children()
->arrayNode('roles')
->requiresAtLeastOneElement()
->prototype('array')
->children()
->scalarNode('name')
->isRequired(true)
->end()
->scalarNode('description')
->end()
->arrayNode('placeholders')
->prototype('scalar')->end()
->end()
->booleanNode('html')
->isRequired()
->defaultValue(true)
->end()
->scalarNode('template')
->isRequired(true)
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
扩展类
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('foo_bar_notify.yml');
$container->setParameter('notify', $config);
}
public function getAlias()
{
return 'foo_bar_notify';
}
主配置文件
foo_bar_notify:
roles:
software_developer:
name: Alice
description: Foo
placeholders:
- $name
- $email
html: true
template: 'some/path'
super_developer:
name: Malfoy
description: bar
html: false
template: 'some/path/over/here'
自定义 yaml (notify.yml)
foo_bar_notify:
roles:
core_developer:
name: core
html: true
template: 'some/path'
【问题讨论】:
标签: php symfony configuration bundle