/** * 保存记录 * @param type $model */ protected static function saveInternal($attributes) { if ($attributes) { foreach ($attributes as $key => $value) { $cmodel = Config::findOne(['`key`' => $key]); if (!$cmodel) { $cmodel = new Config(); $cmodel->key = $key; $cmodel->value = $value ? $value : ''; $cmodel->save(); } else { if ($cmodel->value != $value) { $cmodel->value = $value ? $value : ''; $cmodel->save(); } } if ($key == 'site_language') { //写入语言的配置文件 $configFile = LsYii::getWebPath('/common/config/main-local.php'); FileHelper::writeConfig($configFile, ['language' => $value]); } if ($key == 'datetime_timezone') { //写入时间的配置文件 $configFile = LsYii::getWebPath('/common/config/main-local.php'); FileHelper::writeConfig($configFile, ['timezone' => $value]); } } } return true; }
protected function initOneInternal($id, $defaultValue = '') { $model = Config::findOne(['id' => $id]); if ($model != null) { $this->{$id} = $model->value; } else { if (empty($defaultValue) && $this->{$id} !== null) { $defaultValue = $this->{$id}; } $model = new Config(); $model->id = $id; $model->value = $defaultValue; $model->save(); $this->{$id} = $defaultValue; } }