Symfony2: There is no extension able to load the configuration for

16,948

That's because your code:

$rootNode = $treeBuilder->root('mw_menu'); 

$rootNode
    ->children()
    ->scalarNode('mw_menu')->defaultValue('')->end()
    ->end();

means that the config file should look like this:

mw_menu: 
    mw_menu: "some teststring" 

An example:

To be more specific, you need to adapt your code to whatever node you want. In general, people use a general root, like mw_menu, and then secondary value like database_driver in the following example:

$rootNode = $treeBuilder->root('mw_menu'); 

$rootNode
    ->children()
    ->scalarNode('database_driver')->defaultValue('orm')->end()
    ->end();

Which would then look like this in config file:

mw_menu: 
    database_driver: mongo_db
Share:
16,948
marc
Author by

marc

By day: sleeping At night: trying to study and understand control and system theory

Updated on June 05, 2022

Comments

  • marc
    marc almost 2 years

    I am building an extension to load config files from all installed bundles.

    my Extension looks like this:

    namespace Acme\MenuBundle\DependencyInjection;
    // use ...
    use Acme\MenuBundle\DependencyInjection\Configuration;
    
    class AcmeMenuExtension extends Extension {
        public function load(array $configs, ContainerBuilder $container) {
    
            $configuration = new Configuration();
            $config = $this->processConfiguration($configuration, $configs);
    
            $finder = new \Symfony\Component\Finder\Finder();
            $finder
                ->directories()
                ->in($container->getParameter('kernel.root_dir') . '/../src/*/*Bundle/Resources')
                ->path('config');
    
            $possibleLocations = array();
            foreach ($finder as $c_dir) {
                $possibleLocations[] = $c_dir->getPathName();
            }
             
            $loader = new Loader\YamlFileLoader($container, new FileLocator($possibleLocations));
            $loader->load('menu.yml');
        }
    }
    

    And then there is my (very simple) Configuration class: I will add a more complex tree in the future, but for now I want it to work with this:

    namespace Acme\MenuBundle\DependencyInjection;
    // use ...
    
    class Configuration implements ConfigurationInterface {  
        public function getConfigTreeBuilder() {
            $treeBuilder = new TreeBuilder();
            $rootNode = $treeBuilder->root('mw_menu'); 
    
            $rootNode
                ->children()
                    ->scalarNode('mw_menu')->defaultValue('')->end()
                ->end(); 
    
            return $treeBuilder;
        }
    }
    

    For testing I only placed a "menu.yml" file inside the current MenuBundle\Resources\config with this content:

    # file: src\Acme\MenuBundle\Resource\config\menu.yml
    mw_menu: "some teststring"
    

    For manual testing I use a testAction in a default Controller, which does actually nothing but render an empty template.

    Anyway, I get this error:

    InvalidArgumentException: There is no extension able to load the configuration for     
    "mw_menu" (in {path to symfony}/app/../src/Acme/MenuBundle/Resources\config\menu.yml).
    Looked for namespace "mw_menu", found none
    

    How can I fix that?

    From what I currently understand, Symfony notices the key 'mw_menu' in the config file, but is not able to find the matching configuration.

    I worked along the cookbook article: How to expose a semantic configuration?

    Please note: I know of Knp Menu Bundle and similar Bundles but I do want to implement a menu myself.

    Additionally I found this notice. Is he right?