Where do I put the Symfony2 user settings I need?

I need to have some configuration for my package in Symfony2. Where is the best place to put them?
and how can i get them from there?

I used the default database settings in PARAMETERS.INI But I need additional ones that I can personally get in the code.

+4
source share
4 answers

You should keep your parameters inside packages, for example src/Company/SomeBundle/Resources/config/parameters.yml

+4
source

To define any additional parameters that you need, define them in the config.yml file. Sort of:

 # app/config/config.yml parameters: my_mailer.class: Acme\HelloBundle\Mailer my_mailer.transport: sendmail 

Then you can get them anywhere the service container is available, for example inside the controller, just like you retrieve any other service, such as a doctrine or swiftmailer. For example, in the do controller

 $transport = $this->get('my_mailer.transport'); 

If you want, you can define these parameters in paramters.ini, you will get the same result.

+3
source

See How to open the cookbook assembly Semantic Configuration for the Bundle . One of the advantages of this approach is that you can check the configuration.

+1
source

use the different parts in the parameters.ini file. You may have a prod1 environment using parameters prefixed with prod1 and prod2 with the same:

parameters.ini:

 [parameters] prod1_database_driver = pdo_mysql prod1_database_host = 127.0.0.1 # ... prod2_database_driver = pdo_mysql prod2_database_host = localhost 

They both use the prod.yml configuration, but overwrite the material you want to read from the .ini options:

config_prod1.yml:

 imports: - { resource: config_prod.yml } // .. overwrite stuff here 
0
source

All Articles