1

When we create a bundle 'MyBundle' with console in symfony, it generate class MyBundleExtension.php inside this class we find a method 'load'

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'));
    $loader->load('services.yml');
}

When i dump the parametre $configs the result is an empty array inside array

From where this parametre was injected and how can i add values for this parametre ?

2 Answers 2

2

As Mert Simsek mentioned, you can configure your bundle by adding the configuration in app/config/config.yml

Your bundle has a key that collects this configurations. This key is by default obtain using the bundle name with this function

\Symfony\Component\DependencyInjection\Extension\Extension::getAlias

but you can override this function to define a custom key in your extension.

By default (from the doc of getAlias function) the alias is created like this

* This convention is to remove the "Extension" postfix from the class
* name and then lowercase and underscore the result

so in your case is just "my". if you want to add configuration to this bundle your yml config will look something like this:

my:
    some_config: value
    set_of_configs:
       config1: value1
       config2: value2

After you do this in the load method $configs you will get an array. You can the use the predefined class "Configuration" to validate this configs. You can find more info about bundle configuration in the Symfony Doc here:

https://symfony.com/doc/current/components/config/definition.html

Hope this helps,

Alexandru Cosoi

Sign up to request clarification or add additional context in comments.

Comments

0

You should add you variables into app/config/config.ymlfile.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.