We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Creating and editing a configuration file

Hi

I'm trying to create a configuration file for a 3rd party program, from within my phalcon application..

The data is stored in the phalcon database..

I have a table in the database (and have created a model based on this):

fields: id name option1 option2 option3 groupid

I need to get this written into a text/configuration file in the following manner:

[group1] 
item1 
item2 option option

[group2] 
item3 option 
item4

This is similiar to the Config/Ini class, but that's only for reading...

I could do this with fopen and fwrite and loop through the database entries... but I just want to know if there is a better way to do it...

The best way to enable third party apps to access your app/system is via web API (json). So you keep all your config.ini, database etc. and just read them to present as a (secured) json response via regular HTTP verbs.

Reading the DB and generating an ini file each time a page loads is a waste of resources.... If you want to stick with this approach, I'd strongly recommend a trigger on your SQL table to mark a flag somewhere in a registry table, so when you load your page you check by that flag if the ini needs (re)creation. example: https://stackoverflow.com/questions/6296313/mysql-trigger-after-update-only-if-row-has-changed