直升机,
我正在尝试将自定义配置加载到我的AppBundle中。不幸的是我得到了:
[Symfony的\元器件\ DependencyInjection \异常\ InvalidArgumentException] 没有扩展程序可以加载" app" (在 在/ var / WWW
/dev.investmentopportunities.pl/src/AppBundle/DependencyInjection/../Resour CES /配置/ general.yml)。查找命名空间" app",找不到
有几个与此错误相关的类似主题。我已经查看了它们但无法找到解决此问题的任何解决方案。
我的配置文件如下所示:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('app');
$rootNode
->children()
->arrayNode('tags')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->end()
->scalarNode('role')->isRequired()->end()
->scalarNode('priority')->isRequired()->end()
->scalarNode('label')->isRequired()->end()
->end()
->end();
return $treeBuilder;
}
}
和 general.yml:
app:
tags:
Accepted:
name: "Accepted"
role: "ROLE_ACCEPTTAG"
priority: "3"
label: "label label-info"
Booked:
name: "Booked"
role: "ROLE_ACCOUNTANT"
priority: "3"
label: "label label-info"
Finalized:
name: "Booked"
role: "ROLE_ACCEPTDOC"
priority: "1"
label: "label label-success"
AppExtension.php:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
/**
* This is the class that loads and manages your bundle configuration
*/
class AppExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('app', $config['app']);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('general.yml'); # another file of yours
}
}
答案 0 :(得分:1)
TL; DR:您不应在扩展程序中加载general.yml
文件。
定义捆绑包的配置是关于捆绑包如何处理配置,了解来自config.yml
的配置。
因此,您应该在general.yml
中导入config.yml
文件,它应该有效。
注意:加载器来自Symfony\Component\DependencyInjection\Loader
命名空间,它们用于依赖注入,允许bundle定义服务,主要由第三方bundle使用。