Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Configuration rootNode not recognised

I am trying to define the configuration parameters available to users of my bundle and I'm having a problem getting the root node to be recognised.

I have created a Configuration class with a getConfigTreeBuilder that looks like this:

/**
 * {@inheritdoc}
 */
public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('rally_stats');

    // Here you should define the parameters that are allowed to
    // configure your bundle. See the documentation linked above for
    // more information on that topic.

    $rootNode->children()->arrayNode('projects')
        ->prototype('scalar')->end();

    return $treeBuilder;
}

Using that, I would expect to be able to create a section in config.yml that looks like this:

rally_stats:
    projects:
        - project1
        - project2

and then to be able to access the config with:

$this->getContainer()->getParameter('rally_stats.projects');

However, when trying to load that config I get this error:

[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "rally_stats" 
(in /Users/stu/Projects/rally-stats/app/config/config.yml). Looked for namespace "rally_stats", found "framework", "security", "
twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", 
"wa_ndisco_rally_stats", "jms_di_extra", "jms_aop", "debug", "web_profiler", "sensio_distribution" 
in /Users/stu/Projects/rally-stats/app/config/config.yml 
(which is being imported from "/Users/stu/Projects/rally-stats/app/config/config_dev.yml").

The closest is wa_ndisco_rally_stats, which was the original root name when the bundle was generated by Symfony. I've grepped for that & just wa_ndisco and there are no other references to either.

If I remove the config section & dump-reference for my bundle, I get this:

# Default configuration for "WANdiscoRallyStatsBundle"
rally_stats:
    projects:             []

Why can I not add config using the node name I've provided?

If I do give it the name it thinks it should have wa_ndisco_rally_stats, I can't access it either, I get the same error for that name too.

like image 215
Stuart Grimshaw Avatar asked Jun 08 '26 13:06

Stuart Grimshaw


1 Answers

First of all your configuration is wrong:

$rootNode->children()->arrayNode('projects')
    ->prototype('scalar')->end();

Should be:

$rootNode
    ->children()
        ->arrayNode('projects')
            ->prototype('scalar')->end()
        ->end()
    ->end();

and if you want to acces it from parameters you have to go to your bundle extension class and set it like this for example:

    $container->setParameter('rally_stats.projects', $config['projects']);

Here you can read something about it.

like image 193
vardius Avatar answered Jun 11 '26 21:06

vardius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!