#### 写入配置文件 前台 ~~~ <input type="text" name="WEB_COM" value="{:config('web.WEB_COM')}" placeholder="后面不要加斜杠/" autocomplete="off" class="layui-input"> ~~~ 后台 ~~~ $path = 'application/extra/web.php'; $file = (include $path); $config = array( 'WEB_TIT' => input('WEB_TIT'), 'WEB_COM' => input('WEB_COM')); $res = array_merge($file, $config); $str = '<?php return ['; foreach ($res as $key => $value) { $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ','; } $str .= ']; '; if (file_put_contents($path, $str)) { return tpta('修改成功'); } else { return tptb('修改失败'); } ~~~ #### 写入数据库 前台代码 ~~~ <input type="text" name="site_config[site_title]" value="{$site_config.site_title}" required lay-verify="required" placeholder="请输入网站标题" autocomplete="off" class="layui-input"> ~~~ 后台代码 ~~~ /** * 显示资源列表 * * @return \think\Response */ public function index() { if (Cache::has('site_config')){ //查询缓存 $System['value']=Cache::get('site_config'); }else{ //查询数据库 $System=SystemModel::where('name', 'site_config') -> field('value')->find(); } $site_config = unserialize($System['value']); return $this->fetch('index', ['site_config' => $site_config]); } /** * 提交配置 */ public function updateSiteConfig() { $site_config = $this->request->post('site_config/a'); $value=serialize($site_config); if (SystemModel::where('name', 'site_config')->setField('value' , $value)) { Cache::set('site_config', $value); $this->success('提交成功'); } else { $this->error('提交失败'); } } ~~~