CodeIgniter Forums
Write to config file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Write to config file (/thread-69679.html)



Write to config file - Aleksa95x - 01-04-2018

Hello,

I'm making installation file, how can I write to e.g. database config file with fwrite()?
I want to change value of hostname, username, password, database name. How can I select these particular array elements?


RE: Write to config file - InsiteFX - 01-05-2018

You can create CodeIgniter config.tpl files with dummy values and use
str_replace to replace the dummy values with the inputted values.

1) open and read the ./application/config.tpl config file
2) use str_replace to add the correct values
3) save and write the config.php file to the ./application/config folder

This can be used to write any type of CodeIgniter configuration file.

I'll see if I can give you an example later today.


RE: Write to config file - Aleksa95x - 01-05-2018

Thanks, I know now how to make it! Smile