[CodeIgniter] changing config.php by code |
[eluser]venksster[/eluser]
this is perhaps more of a design question. i am using config.php to store various configurations for my application. In the course of using it, I would like to change the values PERMANANTLY, which means that another instance of a webservice hit would also subsequently use the new values. therefore, $this->config->set_item() is not going to work since i believe thats an in-memory change. is there a way, in terms of either CI's codebase or a design that you could suggest, by which i could programmatically make a permanant change to config.php's array values? going forward, i would potentially also like to write an ADMIN application through which i could make these changes (through form elements) Any ideas? thanks!
[eluser]eoinmcg[/eluser]
if config.php is writeable you can append to or overwrite the file. you'll probably want to think up a way to parse all the values in the file so you can modify them. on another note, there are some concerns about the file being writable
[eluser]BrianDHall[/eluser]
As far as CI's code, no. What you would need to do is basically use regex and you could also make use of CI's file helper to make reading/writing a bit easier. So you'd load up config.php, run a preg/ereg function that looks for "$config['index_page'] = ", then rip out everything after the = and before the ;. Then you'd replace that with whatever you wanted the new value to be. Not really hard I suppose, probably easier than you'd think.
[eluser]BrianDHall[/eluser]
Ah what the hell, one more regex for the day: Code: // $file should contain full text of config.php Untested, but I think it should just about do it. So $key is whatever config item you want to change the value of, and $new_value is what you want to set it to. And then that's it. It's a place for you to start at least ![]()
[eluser]SneakyDave[/eluser]
Sometimes,I'll use Apache Ant to build a config.php (or database.php) based on environment. You can copy a dummy or skeleton config file, and use Ant's replace target to search and replace the things you want to change, then copy the result to the real config.php file. (Assuming the permissions are all setup correctly) http://ant.apache.org/ You'll need a mechanism to launch the ant routine though, whether through a manual process, or through PHP's "exec" function. |
Welcome Guest, Not a member yet? Register Sign In |