Welcome Guest, Not a member yet? Register   Sign In
Write to custom config?

I have created a custom config file and am using CI's config class but how can I write to the new config?

Basically I have a form in the admin panel that is reading the config, I need to be able to change those settings and save them. Any good tutorials or solutions others have come up with?


You might find it easier to store such config in a database, as altering the values of a config files is...well, 'non-trivial' (read: a pain in the ass, at best).

Meanwhile changing db settings are super-easy and relatively pain-free.

It's interesting you say that and I originally thought the same. I've used different CMSs in the past and I've seen them use a mix of DB and .php configs.

I guess I started going down this path because CI has the config class which takes care of half the battle. If it's a real pain to write to then it looks like DB may be the way to go.

Think I'm gonna stay with the text config. It's a beautiful thing when I can load the config in My_Controller and access it globally without having to mess with a query.

And wouldn't you know it, 30 minutes later I come across the answer somwherez. Smile

For those interested:
$File = "YourFile.php";
$Handle = fopen($File, 'w');

$rtn = "\n";
$File = "system/application/config/YourFile.php";
$Handle = fopen($File, 'w');
$Data  = '<?php'.$rtn;
$Data .= '$config["dev_mode"] = 1'.$rtn;
$Data .= '?>'.$rtn;

fwrite($Handle, $Data);
print "Data Written";

[eluser]Mr. Ed[/eluser]
I'll give it a try, buy but you are missing the allready written data in the config file. I'll fight with that.


Have also a look at http://ellislab.com/forums/viewthread/131748/.

Theme © iAndrew 2016 - Forum software by © MyBB