Quick question – I’m trying to decide the best way to store some site variables. I would like build a “control panel” type feature into my site where I can chose settings and they will be reflected throughout my site.
For example – I have one item I’m selling and it has a price (and a picture to display the price). I would like to be able to set this global variable from a custom backend page instead of having to go and change the img src etc..
What is the best way to go about doing this? At first I thought a DB table but then surely it would be a slow(ish) way of accessing only a handful of site variables? I also thought about a file, but was wondering how I would go about overwriting the correct bit when values change etc.
Using your expertise, please could you recommend an avenue to go down (if there is a favourable method), many thanks! (I’m using the Yii framework if anyone else uses it too).
You may want to look into using a properties (.ini) file.
The function
parse_ini_file(string $filename)returns an array of the properties stored by an .ini file.However, php doesn’t have a function to write ini files included, so you will need a custom one. Here is one,
write_ini_file(array $assoc_arr, string $path)which adds an arrays keys and values to the ini file at the given path, replacing old key values with new ones if necessary.