【问题标题】:There is no extension able to load the configuration for ... Looked for namespace "...", found none没有扩展能够加载...的配置 寻找命名空间“...”,没有找到
【发布时间】:2016-09-28 11:53:17
【问题描述】:

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

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 中,而是放在我自己的文件中。

说明
我的 bundle 项目结构如下/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

想法
如果有任何问题或建议不起作用,我将使用信息更新此部分


【问题讨论】:

  • 我假设您已经检查了手册? symfony.com/doc/current/bundles/configuration.html 您的根节点将类似于 tzfrs_spotify 这就是 Symfony 知道特定捆绑包的配置值的方式。也许也可以看看框架包配置文件。
  • 是的,我检查过,但也没有用。

标签: php symfony


【解决方案1】:

确保您的所有内容都拼写正确,并且您的扩展类实际上正在被调用。如果您没有正确命名扩展名,则不会加载它。我刚刚对此进行了测试,它工作正常:

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);
     }
}

【讨论】:

    猜你喜欢
    • 2016-07-03
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2013-09-19
    • 1970-01-01
    • 2019-02-25
    • 2018-04-22
    相关资源
    最近更新 更多