0
votes

I know this post is popular in here, there are a lot of questions about this problem, but nothing helped me to solve my problem. I have to ask this.

I created a bundle named "ATL15/GoogleAnalyticsBundle".

I want to get users parameters from app/config.yml; This is my configuration parameters, i'm loading parameters from 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%"

I did everything i read from symfony documentation book and the web. Nothing helped me at all...

This is my DependencyInjection/Configuration.php file:

<?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;
    }
}

And this is my DependencyInjection/ATL15GoogleAnalyticsBundleExtension.php file:

<?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';
    }
}

And yes, i loaded this bundle from app/AppKernel.php;

    new ATL15\GoogleAnalyticsBundle\ATL15GoogleAnalyticsBundle(),

Everytime i'm getting this error:

[Sat Sep 14 17:37:24 2013] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' with message 'There is no extension able to load the configuration for "atl15_google_analytics" (in /var/www/vsy-bio/src/ATL15/GoogleAnalyticsBundle/DependencyInjection/../Resources/config/config.yml). Looked for namespace "atl15_google_analytics", found none' in /var/www/vsy-bio/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:290\nStack trace:\n#0 /var/www/vsy-bio/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php(260): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->validate(Array, '/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): Symfon in /var/www/vsy-bio/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php on line 290

Could you please help me?

3
Looks like a typo. Try renaming "ATL15GoogleAnalyticsBundleExtension.php" to "ATL15GoogleAnalyticsExtension.php"Touki
Sorry my fault, the correct name is ATL15GoogleAnalyticsExtension.Canser Yanbakan

3 Answers

1
votes

From the looks of your ATL15GoogleAnalyticsExtension and your error it looks like you are loading a file called config.yml from your bundles Resources\config which is using the parameters stated in the app\config\config.yml.

The file ATL15/GoogleAnalyticsBundle/DependencyInjection/../Resources/config/config.yml should only contain the 2 namespace parameters and services like...

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

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

The config data is passed in to the Extension file by $config = $this->processConfiguration($configuration, $configs); rather than you needing to call the file itself so you don't need to load the Resources/config/config.yml unless that actually contains any internal services or parameters for your bundle.

0
votes

There is a foreach that is redundant:

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

Unless you have a config.yml file in your bundle's Resources folder, and you know what you are doing, remove this foreach. The line numbers in the stacktrace that you provided don't match up with your source code, so I guess you edited it afterwards, but I think the error is coming from this config.yml file.

You do not have to call $loader->load(), in order to read the parameters from app/config.yml, it is done automatically.

-1
votes

The error is the name of the Extension class file and also the class name it needs to match the bundle:

should be GoogleAnalyticsExtension instead of ATL15GoogleAnalyticsBundleExtension, the file name needs to be GoogleAnalyticsExtension.php, and change atl15_google_analytics to google_analytics