0

I have a command in Symfony2 and I want to be able to read the devel config from config_dev.yml

I'm trying to retrieve the config in the command execute method like this:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->getContainer()->getParameter('parse');
}

But when I execute the command:

$ php app/console acme:test

It gives me the following error message:

There is no extension able to load the configuration for "acme"

Data in config_dev.yml that I want to retrieve:

acme:
    foo:    "bar"

The command extends containerAwareCommand:

class AcmeCommand extends containerAwareCommand

Any suggestions how to achieve this?

Update

Configuration tree example:

// src/Acme/ApiBundle/DependencyInjection/Configuration.php

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('acme');

    $rootNode
        ->children()
            ->scalarNode('foo')->end()
        ->end() 
    ;

    return $treeBuilder;
}

Extension example:

// src/Acme/ApiBundle/DependencyInjection/AcmeApiExtension.php

public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();
    $config = $this->processConfiguration($configuration, $configs);
    $container->setParameter('acme', $config);

    $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
    $loader->load('services.xml');

config_dev.yml example:

...
acme:
    foo: "bar"
rfc1484
  • 9,441
  • 16
  • 72
  • 123

2 Answers2

0

Did you define the configuration tree like here?

mangelsnc
  • 76
  • 5
  • I don't know how to represent a configuration tree that includes both `config.yml` and `config_dev.yml` ( I can make it work only defining data in `config.yml`, but I don't know how to include also `config_dev.yml` if I have data defined also there) – rfc1484 Feb 26 '15 at 17:00
0

If you're just interested in storing and retrieving arbitrary data from a config file, then you should store it in parameters.yml, rather than config_dev.yml.

Config entries in parameters.yml are allowed to be free-form, as long as they are below the parameters: key, whereas entires in config*.yml files need to conform to a structure defined in your bundle configuration.

You should define the keys for data you want to store in parameters.yml.dist first, however.

Jez
  • 2,384
  • 1
  • 17
  • 31
  • I see what you mean, I've tried it and it works fine. But I would rather like to execute the command with the `--env=` option, in order to dynamically load config from the corresponding `config_.yml` file. – rfc1484 Feb 26 '15 at 17:02