1

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?

2
  • Do you want the form to write the parameters.yml file with new parameters or do you want to store container parameters in database ( possible security issue if others gain acces to your databse ) Commented May 25, 2013 at 18:16
  • Storing them in yml file only is enough. Commented May 25, 2013 at 18:20

1 Answer 1

2

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 :)

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

1 Comment

jeah combined with reading current data with YAML::parse checking for existence of the file and Yaml::dump - thats why i choose to hint you to the configurator ... less work implementing :)

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.