Symfony3:没有可以加载

时间:2016-06-09 18:02:27

标签: php symfony

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

我的扩展程序如下所示:

<?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           

P.S。我已经阅读了Stack Overflow上所有类似的问题

更新

1 个答案:

答案 0 :(得分:0)

我有同样的问题,并修复它。

要注册分机,您需要为分机和分机添加相同的名称。因此,如果您希望将扩展程序设为the_buggest_bot_bot,则必须将扩展程序文件命名为TheBuggestBotBotExtention,并且必须将该程序包命名为TheBuggestBotBotBundle

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

class TheBuggestBotBotBundle extends Bundle
{

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

    return $this->extension;
  }
}