I want to dynamically set database configurations (username, host, password, etc...) placed in app/config/parameters.yml file.
What I mean by "dynamically" is based on some form input.
Is this possible? And if so, how can I do this?
I want to dynamically set database configurations (username, host, password, etc...) placed in app/config/parameters.yml file.
What I mean by "dynamically" is based on some form input.
Is this possible? And if so, how can I do this?
Please have a look at Sensio/SensioDistributionBundle which is already included in the symfony standard edition.
It does exactly what you're looking for. Setting basic parameters in parameters.yml file.
The class performing the actual writing of the parameters.yml is Sensio\DistributionBundle\Configurator\Configurator.
use Sensio\DistributionBundle\Configurator\Configurator;
Now use the configurator in your Controller.
$configurator = new Configurator($this->get('kernel')->getRootDir());
$configurator->mergeParameters(array(
'my_parameter' = 'my_value',
'my_parameter2' = 'my_value2',
));
$configurator->write();
}
The best thing will be looking at the Configurator class itself to understand how it works.
Hope this helps :)