Welcome Guest, Not a member yet? Register   Sign In
How edit config field?
#1

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?
Reply
#2

(This post was last modified: 02-02-2020, 10:12 AM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB