From 777b990fc95201472005284a7c08ecc00aecc165 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Thu, 24 Dec 2015 12:30:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Response::success/error()?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81$msg=E4=BC=A0=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E4=BD=9C=E4=B8=BAcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/library/think/response.php b/library/think/response.php index 561c9b36..0fcd1a86 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -165,16 +165,21 @@ class Response */ public static function success($msg = '', $data = '', $url = '', $wait = 3) { - $result = [ - 'code' => 1, + $code = 1; + if(is_numeric($msg)){ + $code = $msg; + $msg = ''; + } + $result = [ + 'code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url ?: $_SERVER["HTTP_REFERER"], 'wait' => $wait, ]; - $type = Config::get('default_return_type'); + $type = Config::get('default_return_type'); if (IS_AJAX) { - $type = Config::get('default_ajax_return'); + $type = Config::get('default_ajax_return'); } if ('html' == $type) { $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result); @@ -194,16 +199,21 @@ class Response */ public static function error($msg = '', $data = '', $url = '', $wait = 3) { - $result = [ - 'code' => 0, + $code = 0; + if(is_numeric($msg)){ + $code = $msg; + $msg = ''; + } + $result = [ + 'code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait, ]; - $type = Config::get('default_return_type'); + $type = Config::get('default_return_type'); if (IS_AJAX) { - $type = Config::get('default_ajax_return'); + $type = Config::get('default_ajax_return'); } if ('html' == $type) { $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);