CodeIgniter Forums
How to change data from php to config file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: How to change data from php to config file (/showthread.php?tid=75540)



How to change data from php to config file - Kakumi - 02-19-2020

Hi,

I would like to know if it is possible to modify values saved in the default config file via the framework

The goal is to make a setup at the launch of the site for the first time.

I'm using CodeIgniter v4 and i saw that it's possible to change with the v3 with :
PHP Code:
$this->config->set_item('item_name''item_value'); 

But is there a way in the v4 ?

Thank you


RE: How to change data from php to config file - InsiteFX - 02-19-2020

You could make a config template with replaceable parameters and then do a str_replace on them
when finished just move the template to the config folder.

You could also do that for the database config.


RE: How to change data from php to config file - Kakumi - 02-19-2020

(02-19-2020, 07:50 AM)InsiteFX Wrote: You could make a config template with replaceable parameters and then do a str_replace on them
when finished just move the template to the config folder.

You could also do that for the database config.

Thanks, i think i got the idea.
Like that ?

PHP Code:
$configText file_get_contents("writable/template/Config.php");
$configText str_replace("{someVar}"$userInput$configText);

file_put_contents("Config/CustomConfig.php"$configText);