CodeIgniter Forums
How edit config field? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How edit config field? (/showthread.php?tid=75401)



How edit config field? - omid_student - 02-02-2020

Hi
I have field in config.php file named "token"
I need change it for always when use change token
Actually,write new data to file
Maybe?


RE: How edit config field? - InsiteFX - 02-02-2020

I played around with this a little today using CI 4 here is the code, should work for CI 3.

There is no error handling or checks but it doe's work.

I' am planning on writing a config file editor later when I have the time.

PHP Code:
    public function index()
    {
        
$data = [];

        
// The path to the Config file.
        
$fileName APPPATH.'Config\App.php';

        
// Get the Config file contents.
        
$appConfig file_get_contents($fileName);

        
// The string to search for
        
$search  "public ".'$indexPage'." = 'index.php';";
        
        
// The string to replace string with.
        
$replace "public ".'$indexPage'." = '';";
        
        
// The subject is the whole file.
        
$subject $appConfig;

        
// Replace the string with new string value.
        
$ac str_replace($search$replace$subject);

        
// Write the file back out.
        
$result file_put_contents($fileName$ac);

        
/**
         * Dispaly the file in a textarea on output
         * 
         * <label>App Config</label><br>
         * <textarea rows="200" cols="143">
         *      <?php echo $config;?>
         * </textarea>
         */
        
        
$data['config'] = $ac;

        return 
view('welcome_message'$data);
    } 

At least it is something to get you started.

If you use the code make sure you add in protect and check for errors.

You will need to change the paths for CI 3.


RE: How edit config field? - omid_student - 02-02-2020

(02-02-2020, 10:11 AM)InsiteFX Wrote: I played around with this a little today using CI 4 here is the code, should work for CI 3.

There is no error handling or checks but it doe's work.

I' am planning on writing a config file editor later when I have the time.

PHP Code:
public function index()
 {
 
$data = [];

 
// The path to the Config file.
 
$fileName APPPATH.'Config\App.php';

 
// Get the Config file contents.
 
$appConfig file_get_contents($fileName);

 
// The string to search for
 
$search  "public ".'$indexPage'." = 'index.php';";
 
 
// The string to replace string with.
 
$replace "public ".'$indexPage'." = '';";
 
 
// The subject is the whole file.
 
$subject $appConfig;

 
// Replace the string with new string value.
 
$ac str_replace($search$replace$subject);

 
// Write the file back out.
 
$result file_put_contents($fileName$ac);

 
/**
 * Dispaly the file in a textarea on output
 * 
 * <label>App Config</label><br>
 * <textarea rows="200" cols="143">
 *      <?php echo $config;?>
 * </textarea>
 */
 
 
$data['config'] = $ac;

 return 
view('welcome_message'$data);
 } 

At least it is something to get you started.

If you use the code make sure you add in protect and check for errors.

You will need to change the paths for CI 3.

I had guessed
Thanks