我创建了自己的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
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
<?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']);
}
}
}
是错误的?
答案 0 :(得分:63)
另外,请记住配置文件的根密钥必须是Bundle名称的标准化形式。
这是我曾经多次遇到的事情,如果你不了解它,那就很难解决。
示例:如果调用bundle MyFirstAwesomeBundle
,则文件中的根密钥必须为my_first_awesome
。所以camel-case被转换为snake-case,“bundle”这个词被忽略或被删除。
因此,只需让文件中的根密钥与Configuration::getConfigTreeBuilder()
中指定的值完全匹配即可。
如果您不遵守此规则,则会收到There is no extension able to load the configuration
错误。
我希望这将有助于下一个绝望的灵魂谁最终在这个页面...
答案 1 :(得分: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;
}
}
?>
答案 2 :(得分:9)
当您忘记在app / AppKernel.php中启动捆绑包时会发生这种情况:
<?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');
}
}
答案 3 :(得分:5)
此错误也可能是由配置根目录中缺少或无效的services
密钥引起的。看起来应该是这样的:
services:
foo_bar.baz:
class: Foo\BarBundle\Service\BazService