随心的博客

好记性不如个烂笔头,随心记录!

返回顶部

TP6框架 BaseController内 redirect()函数无法跳转

这个需要自定义一个 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');
}

 

posted @ 2021-10-27 13:11  yangphp  阅读(469)  评论(0编辑  收藏  举报