This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Problem with my Configuration.

New topics about Symfony 2 should go here

Problem with my Configuration.

by breal » Thu Apr 30, 2015 10:33 pm

I am start my first project in symfony 2. I use Symfony 2.6.6

My AppKernel.php
Code: Select all
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new AppBundle\AppBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}


And my src/AppBundle/DependencyInjection\AppExtension.php
Code: Select all
<?php
namespace AppBundle\DependencyInjection;

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

class AppExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new YamlFileLoader(
            $container,
            new FileLocator(__DIR__.'/../Resources/config')
        );
        $loader->load('services.yml');


    }
}


My configuration class src/AppBundle/DependencyInjection\Configuration.php
Code: Select all
<?php


namespace AppBundle\DependencyInjection;

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

class Configuration implements ConfigurationInterface
{
    /**
     * Generates the configuration tree.
     *
     * @return TreeBuilder
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('karmed');
        $rootNode->children()->scalarNode('var')->end();

        return $treeBuilder;
    }
}


And part of app/config/config.yml
Code: Select all
karmed:
  var: off


I don't understand why i have this message when i call app/console
Code: Select all
  [Symfony\Component\Config\Exception\FileLoaderLoadException]    There is no extension able to load the configuration for "karmed" (in /home/vstas/data/work/karmed/app/config/config.yml). Looked for namespace "karmed", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "fos_user", "app", "debug", "web_profiler", "sensio_distribution" in /home/vstas/data/work/karmed/app/config/config.yml (which is being imported from "/home/vstas/data/work/karmed/app/config/config_dev.yml"). 


I try remove all files from directory app/cache

I think the problem is configuration loading order, because when i try to change AppExtension to
Code: Select all
.....
class AppExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        print "exit";
        exit();
        $configuration = new Configuration();
.....


Nothing change.
But when i remove from config.yml my part of variables it's exit with my debug message.

Please help me.
breal
Junior Member
 
Posts: 6
Joined: Thu Aug 17, 2006 1:11 pm
Location: Russian Federation

Re: Problem with my Configuration.

by breal » Fri May 01, 2015 1:38 am

May be this answer help anyone.
One good man answered:

It's not that rootnode name that's used for the configuration, but the DI alias of the extension. As it's the AppExtension, it's alias is app. Configure it using app: instead.

However, AppBundle's aren't meant to be reused. It shouldn't use custom configuration things. Just use constants (best practice) or service parameters directly (recommended practice).


http://stackoverflow.com/questions/29976940/symfony2-there-is-no-extension-able-to-load-the-configuration-custom-configura
breal
Junior Member
 
Posts: 6
Joined: Thu Aug 17, 2006 1:11 pm
Location: Russian Federation