From bab4398552522487619ebbff3ad8413a7b35dbba Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 24 Jul 2016 20:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E7=9A=84error=20suc?= =?UTF-8?q?cess=20result=20redirect=E6=96=B9=E6=B3=95=E5=9D=87=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E4=BD=BF=E7=94=A8return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/controller/Jump.php | 42 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/library/traits/controller/Jump.php b/library/traits/controller/Jump.php index 10f2c765..38461b90 100644 --- a/library/traits/controller/Jump.php +++ b/library/traits/controller/Jump.php @@ -27,11 +27,11 @@ trait Jump /** * 操作成功跳转的快捷方法 * @access protected - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 - * @return array + * @param mixed $msg 提示信息 + * @param string $url 跳转的URL地址 + * @param mixed $data 返回的数据 + * @param integer $wait 跳转等待时间 + * @return void */ protected function success($msg = '', $url = null, $data = '', $wait = 3) { @@ -58,16 +58,17 @@ trait Jump $result = ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str')) ->fetch(Config::get('dispatch_success_tmpl'), $result); } - return Response::create($result, $type); + $response = Response::create($result, $type); + throw new HttpResponseException($response); } /** * 操作错误跳转的快捷方法 * @access protected - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 + * @param mixed $msg 提示信息 + * @param string $url 跳转的URL地址 + * @param mixed $data 返回的数据 + * @param integer $wait 跳转等待时间 * @return void */ protected function error($msg = '', $url = null, $data = '', $wait = 3) @@ -102,11 +103,11 @@ trait Jump /** * 返回封装后的API数据到客户端 * @access protected - * @param mixed $data 要返回的数据 - * @param integer $code 返回的code - * @param mixed $msg 提示信息 - * @param string $type 返回数据格式 - * @return mixed + * @param mixed $data 要返回的数据 + * @param integer $code 返回的code + * @param mixed $msg 提示信息 + * @param string $type 返回数据格式 + * @return void */ protected function result($data, $code = 0, $msg = '', $type = '') { @@ -116,16 +117,17 @@ trait Jump 'time' => $_SERVER['REQUEST_TIME'], 'data' => $data, ]; - $type = $type ?: $this->getResponseType(); - return Response::create($result, $type); + $type = $type ?: $this->getResponseType(); + $response = Response::create($result, $type); + throw new HttpResponseException($response); } /** * URL重定向 * @access protected - * @param string $url 跳转的URL表达式 - * @param array|integer $params 其它URL参数 - * @param integer $code http code + * @param string $url 跳转的URL表达式 + * @param array|integer $params 其它URL参数 + * @param integer $code http code * @return void */ protected function redirect($url, $params = [], $code = 302)