没有扩展程序可以加载配置...查找命名空间“...”,找不到

时间:2016-09-28 11:53:18

标签: php symfony

简介
我知道。关于这个确切的话题有成千上万的帖子,但不知怎的,我仍然无法解决这个问题。我总是收到错误

There is no extension able to load the configuration for "first" (in /var/www/app/src/tzfrs/SpotifyBundle/DependencyInjection/../Resources/config/settings.yml). Looked for namespace "first", found none

目的
我创建了一个包并希望有自定义配置选项,但由于它们比普通文件大,我不想把它放在config.yml中,而是放在我自己的文件中。

描述
我的捆绑包的项目结构如下/src/tzfrs/SpotifyBundle

在捆绑包内我创建了文件

  • ./TzfrsSpotifyBundle.php
  • ./DependencyInjection/Configuration.php
  • ./DependencyInjection/TzfrsSpotifyExtension.php
  • ./Resources/config/settings.yml

当然,我已经在AppKernel注册了Bundle,到目前为止,捆绑包的一切正常,除了我要添加的新配置

TzfrsSpotifyBundle

的内容
<?php
namespace tzfrs\SpotifyBundle;

use tzfrs\SpotifyBundle\DependencyInjection\TzfrsSpotifyExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class TzfrsSpotifyBundle extends Bundle
{
}

/DependencyInjection/Configuration.php的内容(仅限于相关信息)

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('first');

    $rootNode
        ->children()
            ->booleanNode('secondary')->defaultTrue()->end()
        ->end();

    return $treeBuilder;
}

./DependencyInjection/TzfrsSpotifyExtension.php的内容(仅限于相关信息)

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('settings.yml');
}

./Resources/config/settings.yml

的内容
first:
    secondary: false


如果出现任何其他问题或建议不起作用,我将使用信息

更新此部分

1 个答案:

答案 0 :(得分:0)

确保拼写正确,并且实际调用了扩展类。如果您没有恰当地命名扩展名,那么它将不会被加载。我刚测试了这个并且工作正常:

cerad_spotify:
    first:
        secondary: false

class CeradSpotifyBundle extends Bundle
{
}

namespace Cerad\SpotifyBundle\DependencyInjection;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('cerad_spotify');
        $rootNode
            ->children()
                ->arrayNode('first')
                    ->children()
                        ->booleanNode('secondary')->end()
                    ->end()
                ->end() // first
            ->end()
        ;
        return $treeBuilder;
    }
}

namespace Cerad\SpotifyBundle\DependencyInjection;

class CeradSpotifyExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();

        $config = $this->processConfiguration($configuration, $configs);

        VarDumper::dump($config);
     }
}