Codeigniter config file change from model or controller
From Codeigniter User Guide - Setting a Config Item
with this:
$this->config->set_item('item_name', 'item_value');
you can change your config item on the fly.
You can just read config files as common files like *.txt
, then parse and change what you need. For example, you want to change value of $config['is_admin_configured']
to TRUE
in config.php
File. Then Below is Example for this. You can modify it for further use.
Example
$out = '';$pattern = '$config[\'is_admin_configured\']';$newValue = 'TRUE';$filename = "application/config/config.php";echo $filename;if (file_exists($filename)) { $file = fopen($filename, 'r+'); while (!feof($file)) { $line = fgets($file); if (strpos($line, $pattern) !== false) { $out .= $pattern . "=" .$newValue .";"; echo $newValue; } else { $out .= $line; } } file_put_contents($filename, $out); fclose($file);} else { echo ' File not found';}