*/ namespace app\wiki\controller; use think\facade\Config; use think\Controller; use think\exception\HttpResponseException; use think\facade\Request; use think\facade\Response; use think\facade\View as ViewTemplate; use think\facade\Url; class Base extends Controller { protected $appInfo; public function checkLogin() { $appInfo = session('app_info'); if ($appInfo) { $this->appInfo = json_decode($appInfo, true); } else { $this->redirect(url('/wiki/login')); } } public function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) { if (is_null($url)) { $url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);'; } elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) { $url = Url::build($url); } $type = 'html'; $result = [ 'code' => 0, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait, ]; if ('html' == strtolower($type)) { $template = Config::get('template'); $view = Config::get('view_replace_str'); $result = ViewTemplate::instance($template, $view) ->fetch(Config::get('dispatch_error_tmpl'), $result); } $response = Response::create($result, $type)->header($header); throw new HttpResponseException($response); } public function success($msg = '', $url = null, $data = '', $wait = 3, array $header = []) { if (is_null($url) && !is_null(Request::instance()->server('HTTP_REFERER'))) { $url = Request::instance()->server('HTTP_REFERER'); } elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) { $url = Url::build($url); } $type = 'html'; $result = [ 'code' => 1, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait, ]; if ('html' == strtolower($type)) { $template = Config::get('template'); $view = Config::get('view_replace_str'); $result = ViewTemplate::instance($template, $view) ->fetch(Config::get('dispatch_success_tmpl'), $result); } $response = Response::create($result, $type)->header($header); throw new HttpResponseException($response); } }