Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

symfony - There is no extension able to load the configuration for "facebookbundle" symfony2

I create my own FacebookBundle and

I got this error:

There is no extension able to load the configuration for "facebookbundle" (in /facebookx/app/config/config_dev.yml). Looked for namespace "facebookbundle", found "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"

The error message means that I got an entry "facebookbundle" in My config.yml which is not used by any extension ?

My 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]

My DFacebookExtension

<?php

namespace DFacebookBundleDependencyInjection;

use SymfonyComponentDependencyInjectionContainerBuilder;
use SymfonyComponentConfigFileLocator;
use SymfonyComponentHttpKernelDependencyInjectionExtension;
use SymfonyComponentDependencyInjectionLoader;

/**
 * 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 LoaderYamlFileLoader($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']);
        }
    }
}

were is error ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Also, keep in mind that the root key of the configuration file must be a normalized form of the Bundle's name.

This is something I've encoutered a few times and it's very frustrating to solve if you're not aware of it.

Example: if bundle is called MyFirstAwesomeBundle, then the root key in the file must be my_first_awesome. So camel-case is converted to snake-case and the word "bundle" is ignored or stripped away.

So simply having the root key in your file match exactly the value specified in Configuration::getConfigTreeBuilder() is not enough.

If you don't follow this rule, then you'll get the There is no extension able to load the configuration error.


I hope this will help the next desperate soul who ends up on this page...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...