// +---------------------------------------------------------------------- declare (strict_types = 1); namespace addon\blog\controller\backend; use think\facade\Request; use think\facade\View; use think\facade\Config; use think\facade\Cache; use ywxapp\controller\BackendBase; /** * Setting 类 * * @author ywxapp */ class Setting extends BackendBase { /** * Summary of needLogin * @var array */ /** * Summary of needRight * @var array */ protected $noNeedVerify = ['*']; /** * 控制器初始化 _initialize * @return void */ protected function initialize() {} /** * 系统设置首页 */ public function index() { $settings = [ 'site' => Config::get('site'), 'seo' => Config::get('seo'), 'email' => Config::get('email'), 'upload' => Config::get('upload') ]; return View::fetch('setting/index', ['settings' => $settings]); } /** * 基本设置 */ public function site() { if (Request::isPost()) { $data = Request::post(); $this->saveConfig('site', $data); return json(['code' => 1, 'msg' => '基本设置已保存']); } $settings = Config::get('site'); return View::fetch('setting/site', ['settings' => $settings]); } /** * SEO设置 */ public function seo() { if (Request::isPost()) { $data = Request::post(); $this->saveConfig('seo', $data); return json(['code' => 1, 'msg' => 'SEO设置已保存']); } $settings = Config::get('seo'); return View::fetch('setting/seo', ['settings' => $settings]); } /** * 邮件设置 */ public function email() { if (Request::isPost()) { $data = Request::post(); $this->saveConfig('email', $data); return json(['code' => 1, 'msg' => '邮件设置已保存']); } $settings = Config::get('email'); return View::fetch('setting/email', ['settings' => $settings]); } /** * 保存配置 */ private function saveConfig($key, $data) { $configFile = app_path() . 'config/' . $key . '.php'; $content = "