问题描述
我创建了自己的 FacebookBundle 和
I create my own FacebookBundle and
我收到此错误:
没有能够加载配置的扩展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",但没有被任何扩展使用?
The error message means that I got an entry "facebookbundle" in My config.yml which is not used by any extension ?
我的 config.yml
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]
我的 DFacebook 扩展
My 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 类来定义你的包配置.
In order for custom config parameters to be accepted you have to define your bundle configuration using a Configuration.php class within your bundle.
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;
}
}
?>
这篇关于没有能够加载“facebookbundle"配置的扩展程序.symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!