• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write to custom config?

#1
[eluser]spmckee[/eluser]
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?

Thanks!

#2
[eluser]BrianDHall[/eluser]
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.

#3
[eluser]spmckee[/eluser]
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.

#4
[eluser]spmckee[/eluser]
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:
Code:
<?php
$File = "YourFile.php";
$Handle = fopen($File, 'w');
?>

<?php
$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";
fclose($Handle);
?>

#5
[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.

Thanks!

#6
[eluser]pistolPete[/eluser]
Have also a look at http://ellislab.com/forums/viewthread/131748/.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.