很多人在使用thinkphp的redirect在跳转时,会遇到它不起作用,可以使用我的方法
在BaseContoller里新建个方法,代码如下
/** * URL重定向 自带重定向无效 * @access protected * @param string $url 跳转的URL表达式 * @param array|integer $params 其它URL参数 * @param integer $code http code * @param array $with 隐式传参 * @return void */ protected function redirect($url, $params = [], $code = 302, $with = []) { $response = Response::create($url, 'redirect'); if (is_integer($params)) { $code = $params; $params = []; } $response->code($code)->with($params); throw new HttpResponseException($response); }
然后继承这个类之后,在你要调用的地方调用就行了
如:
return $this->redirect(‘url’');本文由37°5【https://www.alvinxiao.com 】【https://blog.alvinxiao.com】原创,转载请注明来源。请注意原创和打造和谐的网络环境,谢谢!