Php 没有扩展插件可以加载“的配置”;我的“你的名字”;

Php 没有扩展插件可以加载“的配置”;我的“你的名字”;,php,symfony,dependency-injection,bundle,Php,Symfony,Dependency Injection,Bundle,我知道这篇文章在这里很受欢迎,关于这个问题有很多问题,但是没有什么能帮助我解决我的问题。我不得不问这个问题 我创建了一个名为“ATL15/GoogleAnalyticsBundle”的包 我想从app/config.yml获取用户参数;这是我的配置参数,我正在从app/parameters.yml加载参数 atl15_google_analytics: client_id: "%ga_client_id%" client_secret: "%ga_client_secret%"

我知道这篇文章在这里很受欢迎,关于这个问题有很多问题,但是没有什么能帮助我解决我的问题。我不得不问这个问题

我创建了一个名为“ATL15/GoogleAnalyticsBundle”的包

我想从app/config.yml获取用户参数;这是我的配置参数,我正在从app/parameters.yml加载参数

atl15_google_analytics:
    client_id:  "%ga_client_id%"
    client_secret: "%ga_client_secret%"
    developer_key: "%ga_developer_key%"
    redirect_uri: "%ga_redirect_uri%"
我做了所有我从symfony文档书和网络上读到的事情。什么都帮不了我

这是我的
DependencyInjection/Configuration.php
文件:

<?php

namespace ATL15\GoogleAnalyticsBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder,
    Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('atl15_google_analytics');

        $rootNode->children()
                    ->scalarNode('client_id')->isRequired()->cannotBeEmpty()->end()
                    ->scalarNode('client_secret')->isRequired()->cannotBeEmpty()->end()
                    ->scalarNode('developer_key')->isRequired()->cannotBeEmpty()->end()
                    ->scalarNode('redirect_uri')->isRequired()->cannotBeEmpty()->end()
                 ->end();

        //var_dump($rootNode); die;

        return $treeBuilder;
    }
}
<?php

namespace ATL15\GoogleAnalyticsBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension,
    Symfony\Component\DependencyInjection\Loader;

class ATL15GoogleAnalyticsExtension extends Extension
{
    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'));

        foreach (array('config') as $basename) {
            $loader->load(sprintf('%s.yml', $basename));
        }

        foreach (array('client_id', 'client_secret', 'developer_key', 'redirect_uri') as $attribute) {
            $container->setParameter($attribute, $config[$attribute]);
        }
    }

    public function getAlias()
    {
        return 'atl15_google_analytics';
    }
}
是的,我从
app/AppKernel.php
加载了这个包

    new ATL15\GoogleAnalyticsBundle\ATL15GoogleAnalyticsBundle(),
每次我遇到这个错误时:

[Sat Sep 14 17:37:24 2013][error][client 127.0.0.1]PHP致命错误: 未捕获异常 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' 消息“没有扩展插件能够加载的配置” “atl15谷歌分析”(在 /var/www/vsy-bio/src/ATL15/GoogleAnalyticsBundle/DependencyInjection/。/Resources/config/config.yml)。 查找命名空间“atl15_google_analytics”,在中找不到 /var/www/vsy-bio/vendor/symfony/symfony/src/symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:290\n堆栈 跟踪:\n#0 /var/www/vsy-bio/vendor/symfony/symfony/src/symfony/Component/DependencyInjection/Loader/YamlFileLoader.php(260): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->validate(数组、, “/var/www/vsy-bi…”)\n#1 /var/www/vsy-bio/vendor/symfony/symfony/src/symfony/Component/DependencyInjection/Loader/YamlFileLoader.php(44): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->loadFile('/var/www/vsy bi…')\n#2 /var/www/vsy-bio/src/ATL15/GoogleAnalyticsBundle/DependencyInjection/ATL15GoogleAnalyticsExtension.php(28): 辛丰 /var/www/vsy-bio/vendor/symfony/symfony/src/symfony/Component/DependencyInjection/Loader/YamlFileLoader.php 在线290


您能帮助我吗?

错误是扩展类文件的名称,以及它需要与捆绑包匹配的类名:


应为GoogleAnalyticsExtension而不是ATL15GoogleAnalyticsBundleExtension,文件名应为GoogleAnalyticsExtension.php,从
ATL15GoogleAnalyticsExtension
的外观将atl15_google_analytics更改为google_analytics

,并且您的错误显示您正在从bundles Resources\config中加载一个名为
config.yml
的文件,该文件使用
app\config\config.yml
中所述的参数

文件
ATL15/GoogleAnalyticsBundle/DependencyInjection/./Resources/config/config.yml
应该只包含两个名称空间
参数
服务
类似于

parameters:
    atl15_google_analytics.something.class: ATL15/GoogleAnalyticsBundle...

services:
    atl15_google_analytics.something.services:
        class: %atl15_google_analytics.something.class%

配置数据通过
$config=$this->processConfiguration($configuration,$configs)传递到扩展文件
而不需要调用文件本身,因此不需要加载
资源/config/config.yml
,除非它实际上包含捆绑包的任何内部服务或参数。

有一个foreach是冗余的:

foreach (array('config') as $basename) {
    $loader->load(sprintf('%s.yml', $basename));
}
除非您的bundle的Resources文件夹中有config.yml文件,并且您知道自己在做什么,否则请删除此foreach。您提供的stacktrace中的行号与源代码不匹配,因此我猜您后来编辑了它,但我认为错误来自这个config.yml文件


您不必调用$loader->load(),以便从app/config.yml读取参数,这是自动完成的。

这是正确的。演示捆绑包名为
AcmeDemoExtension
not
DemoExtension
捆绑包名称为GoogleAnalytics而不是ATL15GoogleAnalytics,我以捆绑包的名称命名,对我有效
我创建了一个名为“ATL15/GoogleAnalyticsBundle”的捆绑包。
尝试运行
php应用程序/控制台-n生成:捆绑包--命名空间=“ATL15/GoogleAnalyticsBundle“
。生成的DependencyInjection文件夹名为
ATL15GoogleAnalyticsExtension
很抱歉,我明白你的意思了,我试过了。我想可能是名称空间的问题,因为他都有大写字母,我想这可能是问题所在。我相信我的建议会奏效,从bundle名称和其他类名中删除名称空间名称。看起来像是输入错误。尝试将“ATL15GoogleAnalyticsBundleExtension.php”重命名为“ATL15GoogleAnalyticsExtension.php”对不起,我的错误是,正确的名称是ATL15GoogleAnalyticsExtension。配置文件中的参数将没有默认数据。用户应在app/config.yml中定义其值。我的捆绑包的config.yml中只有必需的参数。您的
Resources/config/config.yml
的布局是否如上所述或类似于
app/config/config.yml
,捆绑包别名作为名称空间?当我在我的app/config/config.yml中复制而没有值时,只需键入“”,就会出现此错误。现在是空的,我不知道那是什么意思
app/config/config.yml
应该具有所有的symfony设置,如。如果它是空的,那么您将遇到其他问题,例如没有db连接参数或框架设置。我的错。它不是app/config/config.yml,而是bundle的config.yml。是空的,兄弟。很抱歉