這個需要自定義一個 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'); }