gpt4 book ai didi

symfony - 没有扩展能够加载 “facebookbundle” symfony2的配置

转载 作者:行者123 更新时间:2023-12-03 09:13:14 29 4
gpt4 key购买 nike

我创建了自己的FacebookBundle,

我收到此错误:

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"



该错误消息表示我在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']);
}
}
}

是错误吗?

最佳答案

为了接受自定义配置参数,您必须使用包中的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;
}
}
?>

关于symfony - 没有扩展能够加载 “facebookbundle” symfony2的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13741632/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com