Answer the question
In order to leave comments, you need to log in
How to store user preferences in Symfony?
Hello.
Just starting to learn Symfony, a question arose.
I need to save/read the settings of my application.
After reading the documentation, I realized that in Symfony it is better to store settings in YML files.
So, I created a YML file (setting.yml), for example:
organization:
office_1:
set_1: "example_1"
set_2: "example_2"
...
office_2:
set_1: "example_1"
set_2: "example_2"
...
$value = Yaml::parseFile($this->get('kernel')->getRootDir() . '/setting.yml');
$yaml = Yaml::dump($array);
file_put_contents('/setting.yaml', $yaml);
Answer the question
In order to leave comments, you need to log in
The format doesn't really matter. Sympha supports yaml, xml, php.
Another question is what if these are real application settings and they are not dynamic, but permanent, like passwords, databases, etc. Then use the parameters:
https://symfony.com/doc/current/service_container/...
At the expense of overwriting the file - you read its contents, change what you need in the resulting array and save it with your method. I did. But this option is for rare work at the same time by only one person (for example, an administrator). If several people should work with this file at the same time, then, as written above, you must use the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question