首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >没有能够加载"facebookbundle“symfony2配置的扩展

没有能够加载"facebookbundle“symfony2配置的扩展
EN

Stack Overflow用户
提问于 2012-12-06 18:29:23
回答 4查看 67.8K关注 0票数 34

我创建了自己的FacebookBundle

我得到了这个错误:

没有能够加载"facebookbundle“配置的扩展(在/facebookx/app/config/config_dev.yml中)。查找名称空间"facebookbundle",找到“框架”、“安全”、“细枝”、"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“

这条错误消息意味着我的config.yml中有一个条目"facebookbundle“,没有被任何扩展使用?

我的config.yml

代码语言:javascript
复制
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]

我的DFacebookExtension

代码语言:javascript
复制
<?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']);
        }
    }
}

哪里是错误?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-12-06 20:11:51

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

src/FacebookBundle/DependencyInjection/Configuration.php:

代码语言:javascript
复制
<?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;
    }
}
?>
票数 25
EN

Stack Overflow用户

发布于 2016-02-19 20:18:07

此外,请记住,配置文件的根密钥必须是捆绑包名称的规范化形式。

这是我已经困扰了几次的问题,如果你没有意识到这一点,那么解决它是非常令人沮丧的。

示例:如果包的名称为MyFirstAwesomeBundle,则文件中的根密钥必须为my_first_awesome。因此,驼峰大小写被转换为蛇形大小写,"bundle“这个词被忽略或去掉了。

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

如果你不遵循这个规则,那么你会得到There is no extension able to load the configuration错误。

我希望这能帮助下一个在这一页结束的绝望灵魂...

票数 73
EN

Stack Overflow用户

发布于 2012-12-06 18:58:53

当您忘记启动app/AppKernel.php中的捆绑包时,就会出现这种情况:

代码语言:javascript
复制
<?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');
   }

}
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13741632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档