创建我自己的FacebookBundle和没有扩展能够加载配置“facebookbundle” Symfony2的
我得到这个错误:
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"
该错误消息意味着我得到了一个条目“facebookbundle “在我的config.yml中没有被任何扩展名使用?
我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']);
}
}
}
均是错误?
okej,谢谢。你现在我怎么能在我的课堂上获得这些数据(例如app_id,秘密)? –
我编辑了我的答案,以包含基于您原始YML配置格式的基本配置定义。我没有测试过,所以可能需要稍微调整一下。 – lifo
我的问题可能会揭示一些 - http:// stackoverflow。com/questions/32482622/creating-a-configuration-file-in-symfony2/32502618#32502618 – Peter