没有扩展程序可以加载"facebookbundle"symfony2的配置

Tho*_*lby 29 symfony

我创建了自己的FacebookBundle和

我收到了这个错误:

没有扩展程序可以加载"facebookbundle"的配置(在/facebookx/app/config/config_dev.yml中).寻找命名空间"facebookbundle",找到"framework","security","twig","monolog","swiftmailer","assetic","doctrine","sensio_framework_extra","jms_aop","jms_di_extra","jms_security_extra ","d_facebook","d_user","d_security","web_profiler","sensio_distribution"

错误消息意味着我在My config.yml中有一个条目"facebookbundle",任何扩展都没有使用它?

我的config.yml

facebookbundle:
    file:   %kernel.root_dir%/../src/FacebookBundle/Facebook/FacebookInit.php
    alias:  facebook
    app_id: xxx
    secret: xxx
    cookie: true
    permissions: [email, user_birthday, user_location, user_about_me]
Run Code Online (Sandbox Code Playgroud)

我的DFacebookExtension

<?php

namespace D\FacebookBundle\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
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class DFacebookExtension 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');

        foreach (array('app_id', 'secret', 'cookie', 'permissions') as $attribute) {
            $container->setParameter('facebookbundle.'.$attribute, $config[$attribute]);
        }

        if (isset($config['file']) && $container->hasDefinition('acebookbundle.api')) {
            $facebookApi = $container->getDefinition('facebookbundle.api');
            $facebookApi->setFile($config['file']);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

是错误?

Rad*_*zea 66

另外,请记住配置文件的根密钥必须是Bundle名称的规范化形式.

这是我曾经多次遇到的事情,如果你不了解它,解决它会非常令人沮丧.

示例:如果调用了bundle MyFirstAwesomeBundle,则必须是文件中的根密钥my_first_awesome.所以camel-case被转换为snake-case,"bundle"这个词被忽略或被剥离.

因此,简单地让文件中的根密钥与指定的值完全匹配Configuration::getConfigTreeBuilder()是不够的.

如果您不遵循此规则,那么您将收到There is no extension able to load the configuration错误.


我希望这将有助于下一个绝望的灵魂谁最终在这个页面...

  • 你的包依赖目录中是否存在“YourBundleExtension”?在某些情况下,这个原因会使 **没有扩展能够加载配置** 错误发生。 (2认同)

lif*_*ifo 22

为了接受自定义配置参数,您必须使用捆绑包中的Configuration.php类来定义捆绑配置.

SRC/FacebookBundle/DependencyInjection/configuration.php文件:

<?php
namespace FacebookBundle\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/extension.html#cookbook-bundles-extension-config-class}
 */
class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('facebookbundle');

        $rootNode
            ->children()
                ->scalarNode('file')->defaultValue('')->end()
                ->scalarNode('alias')->defaultValue('')->end()
                ->scalarNode('app_id')->defaultValue('')->end()
                ->scalarNode('secret')->defaultValue('')->end()
                ->booleanNode('cookie')->defaultTrue()->end()
                ->arrayNode('permissions')
                    ->canBeUnset()->prototype('scalar')->end()->end()
            ->end()
            ;

        return $treeBuilder;
    }
}
?>
Run Code Online (Sandbox Code Playgroud)


Alt*_*PHP 10

当你忘记在app/AppKernel.php中启动bundle时会发生这种情况:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{

   public function registerBundles()
   {
      $bundles = array (
              new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
              new Symfony\Bundle\SecurityBundle\SecurityBundle(),
              new Symfony\Bundle\TwigBundle\TwigBundle(),
              new Symfony\Bundle\MonologBundle\MonologBundle(),
              new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
              new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
              new Symfony\Bundle\AsseticBundle\AsseticBundle(),
              new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
              new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
              //...
              new D\FacebookBundle\DFacebookBundle(),
              //...
      );

      if (in_array($this->getEnvironment(), array ('dev', 'test')))
      {
         $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
         $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
         $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
      }

      return $bundles;
   }

   public function registerContainerConfiguration(LoaderInterface $loader)
   {
      $loader->load(__DIR__ . '/config/config_' . $this->getEnvironment() . '.yml');
   }

}
Run Code Online (Sandbox Code Playgroud)


Jon*_*han 6

此错误也可能是由于services配置根目录中的密钥丢失或无效而引起的。它看起来应该像这样:

services:
    foo_bar.baz:
        class: Foo\BarBundle\Service\BazService
Run Code Online (Sandbox Code Playgroud)