From 00cab3494598a39e3e7bbcefb7820510382b2931 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 29 May 2016 11:11:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bcontroller=E7=B1=BB=E7=9A=84r?= =?UTF-8?q?edirect=E6=96=B9=E6=B3=95=E5=92=8C=E5=8A=A9=E6=89=8B=E5=87=BD?= =?UTF-8?q?=E6=95=B0redirect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 8 ++++++-- library/traits/controller/Jump.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/helper.php b/helper.php index 0a458e5b..f7ac2303 100644 --- a/helper.php +++ b/helper.php @@ -407,11 +407,15 @@ function xml($data = [], $code = 200, $options = []) /** * 获取\think\response\Redirect对象实例 * @param mixed $url 重定向地址 支持Url::build方法的地址 + * @param array|integer $params 额外参数 * @param integer $code 状态码 - * @param array $params 额外参数 * @return \think\response\Redirect */ -function redirect($url = [], $code = 302, $params = []) +function redirect($url = [], $params = [], $code = 302) { + if (is_integer($params)) { + $code = $params; + $params = []; + } return Response::create($url, 'redirect')->code($code)->params($params); } diff --git a/library/traits/controller/Jump.php b/library/traits/controller/Jump.php index 6d2b9967..ae5aaf90 100644 --- a/library/traits/controller/Jump.php +++ b/library/traits/controller/Jump.php @@ -105,13 +105,17 @@ trait Jump * URL重定向 * @access protected * @param string $url 跳转的URL表达式 + * @param array|integer $params 其它URL参数 * @param integer $code http code - * @param array $params 其它URL参数 * @return void */ - public function redirect($url, $code = 301, $params = []) + public function redirect($url, $params = [], $code = 302) { $response = new Redirect($url); + if (is_integer($params)) { + $code = $params; + $params = []; + } $response->code($code)->params($params); throw new HttpResponseException($response); }