直升机,
我正在尝试将自定义配置加载到我的AppBundle中 . 不幸的是我得到了:
[Symfony \ Component \ DependencyInjection \ Exception \ 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
}
}
1 回答
TL; DR:您不应在扩展名中加载
general.yml
文件 .定义捆绑包的配置是关于捆绑包如何处理配置,了解来自
config.yml
的配置 .所以你应该在
config.yml
中导入general.yml
文件,它应该可以工作 .注意:加载器来自
Symfony\Component\DependencyInjection\Loader
命名空间,它们用于依赖注入,以允许bundle定义服务,主要由第三方bundle使用 .