Answer the question
In order to leave comments, you need to log in
How to store default values in a file and write the rest to the database?
Hello.
Actually the question is the following:
There are user rights. I would like to store the rights by default in a file, and edit it in the same place, for example, in YML, and everything that the user adds is to file it into the database, respectively. How to distinguish between a database and a file? Given that the user will have a getPermissions() method, which should return a set of objects, regardless of where they are stored.
Or write all default values with fixtures/migrations?
But here the question arises, even if you store everything in the database and do not violate the integrity of the data, then you need to somehow solve the issue of assigning default values to the user. Those. you need to somehow do ->setPermission(/*And here there should be an entity from the database*/) , i.e. then you need to somehow search first in the database for this entity by Alias and then only assign it.
Answer the question
In order to leave comments, you need to log in
It is better to make the default rights in the database and upload it from a file if you really need it. For example, where user=0. The database is faster than the file system.
1. create a file like config.php with an array "parameter" => "value", 2. create a table in the database with two columns "parameter" and "value". 3. When initializing the application, first read the array from the config, then all the settings from the database (with their conversion into the same array) and merge these two arrays into one, overwriting the values from the database with the values from the config if the settings are the same.
There don't seem to be any pitfalls.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question