【问题标题】:Symfony3: There is no extension able to load the configuration forSymfony3:没有扩展能够加载配置
【发布时间】:2016-06-09 18:02:26
【问题描述】:

我正在构建一个扩展来从所有已安装的捆绑包中加载配置文件。

我的扩展看起来像这样:

<?php

namespace TheBuggestBot\BotBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class TheBuggestBotBotExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    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');
    }
}

我做了所有我从 symfony 文档书和网络上读到的东西。对我没有任何帮助...

这是我的 DependencyInjection/Configuration.php 文件:

<?php

namespace TheBuggestBot\BotBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
 * This is the class that validates and merges configuration from your app/config files.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('the_buggest_bot_bot');

        $rootNode
            ->children()
                ->arrayNode('ircbot')
                    ->children()
                        ->scalarNode('server')->end()
                        ->integerNode('port')->end()
                        ->scalarNode('username')->end()
                        ->scalarNode('password')->end()
                        ->scalarNode('chanel')->end()
                    ->end()
                ->end()
            ->end()
        ;


        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        return $treeBuilder;
    }
}

我的资源/config/config.yml:

the_buggest_bot_bot:
    ircbot:
        server:   ""
        port:     6667
        username: ""
        password: ""
        chanel:   ""

错误是:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]                                           
  There is no extension able to load the configuration for "thebuggestbot" (in /home/dm3ch/TheBuggestBot/test/src/The  
  BuggestBot/BotBundle/DependencyInjection/../Resources/config/config.yml). Looked for namespace "thebuggestbot", fou  
  nd none           

附:我已阅读 Stack Overflow 上的所有类似问题

更新

【问题讨论】:

  • 你的捆绑名称中真的有 BotBot 吗?TheBuggestBotBotExtension?前缀必须完全匹配。
  • 是的,包的名称是 TheBuggestBotBotBundle。我尝试使用 the_buggest_bot_bot 作为 symfony 生成,它也不起作用。
  • 在你的扩展中粘贴一个 die 语句,只是为了验证它正在被加载。我仍然怀疑它不是。不用说,确保捆绑包也在 AppKernel 中。
  • 我在扩展类的加载函数中添加了 die。它以死亡消息退出。所以调用了加载函数

标签: php symfony


【解决方案1】:

我有同样的问题,并解决它。

要注册一个扩展,你需要为 bundle 和你的扩展具有相同的名称。所以,如果你想启用你的扩展为the_buggest_bot_bot,你的扩展文件必须命名为TheBuggestBotBotExtention,并且bundle必须命名为TheBuggestBotBotBundle

或者,如果您不想更改 Bundle 名称,则必须将扩展名重命名为与 bundle 相同的名称。或者您可以手动注册扩展:

class TheBuggestBotBotBundle extends Bundle
{

  public function getContainerExtension()
  {
    if ($this->extension === null) {
        $this->extension = new TheBuggestBotBotExtension();
    }

    return $this->extension;
  }
}

【讨论】:

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