.Yml parameter for package, symfony2

I was wondering if it is possible to define the parameters.yml file for each package or only for the packages that need it and load them.

I searched a lot, but I can not find such a solution.

+8
php symfony doctrine
source share
2 answers

You need to clarify a bit; Do you want each pool to automatically include the parameters.yml file? I'm afraid you will need to change the core of Symfony DI. However, there is an easy alternative.

If you create your own package with some DependencyInjection , you can add $loader->load('parameters.yml'); to the package extension class.

The extension class must be located in YourBundle/DependencyInjection/YourBundleExtension.php .

The class should look like this

 class YourBundleExtension extends Extension { /** * {@inheritDoc} */ 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'); $loader->load('parameters.yml'); // Adding the parameters file } } 

So, in this case, the parameters.yml file will be in YourBundle/Resources/config/parameters.yml .

+15
source share

If you just want to include the parameters file from the kit into your configuration, just follow the normal format to import additional configuration files from packages (the default application shows how to do this with routing). Update the configuration to include the parameter file as follows:

 imports: - { resource: parameters.yml } - { resource: @YourBundle/Resources/config/parameters.yml } - { resource: security.yml } - ... 

Your settings file must follow the same format as the default:

 parameters: my.parameter: "my value" 
+2
source share

All Articles