我的应用程序由多个名为HelloWorldAdminBundle
, HelloWorldUserBundle
,的包组成HelloWorldDemoBundle
。这会产生一个配置根,如hello_world_demo
,hello_world_user
和hello_world_demo
。我希望我的包的配置根是helloworld_demo
,helloworld_user
和helloworld_admin
. 在这一点上我不得不提到,这并不是一个真正的技术问题,而更多的是一个审美问题。
我试图实现一个自定义扩展并将其注册到 Bundle 中:
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->registerExtension(new HelloworldDemoExtension());
}
扩展:
...
class HelloworldDemoExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function getAlias()
{
return 'hello_world_demo';
}
}
最后是配置:
...
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('helloworld_demo');
...
return $treeBuilder;
}
}
我按照如何为 Bundle 公开语义配置的说明进行操作,但是当我向其中添加项目时,config.yml
出现以下错误:
There is no extension able to load the configuration for "helloworld_demo"