这个需要自定义一个 rediectTo方法,放到 BaseController 里面
/** * 自定义重定向方法 * @param $args */ public function redirectTo(...$args) { // 此处 throw new HttpResponseException 这个异常一定要写 throw new HttpResponseException(redirect(...$args)); }
然后在 BaseController初始化方法里面就可以调用了
//登录验证 $check_res = $this->adminLoginCheck(); if ($check_res['status']=='SUCCESS') { $this->admin_info = $check_res['data']; $this->admin_id = $this->admin_info['admin_id']; }else{ return $this->redirectTo('/admin/login/index'); }