1. 程式人生 > >thinkphp配置檔案動態修改

thinkphp配置檔案動態修改

話不多說直接貼方法

protected function update_config($new_config, $config_file = '') {
    !is_file($config_file) && $config_file = CONF_PATH . '/config.php';

    if (is_writable($config_file)) {
        $config = require $config_file;

       $config = array_merge($config, $new_config);
       file_put_contents(
$config_file, "<?php \nreturn " . stripslashes(var_export($config, true)) . ";", LOCK_EX); @unlink(RUNTIME_FILE); return true; } else { return false; } }
 
 

呼叫方法

$config_file = './config.php';
$config = implode( $config_file);
$new_config = array(
    'MAXUSERNUM' 
=> 1500, ); $this->update_config($new_config, $config_file);