From 843a7262038365b40beee8dcf962257147df450e Mon Sep 17 00:00:00 2001 From: huangdijia Date: Wed, 23 Dec 2015 13:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83Response=E4=B8=ADresult/succe?= =?UTF-8?q?ss/error=E6=96=B9=E6=B3=95=E4=BD=BF=E7=94=A8=EF=BC=8C=E4=B8=8Ev?= =?UTF-8?q?iew=E4=BD=BF=E7=94=A8=E6=96=B9=E6=B3=95=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=8C=E5=90=8C=E6=97=B6=E5=AE=8C=E7=BE=8E?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B9=E6=B3=95=EF=BC=9A=20if(false){=20?= =?UTF-8?q?=20=20=20=20return=20Response::error('error=20msg');=20}else{?= =?UTF-8?q?=20=20=20=20=20return=20Response::success('success=20msg');=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 2 +- library/think/response.php | 38 +++++++++++++------------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index e403b31e..c28bf47a 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -111,7 +111,7 @@ class App // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); // 输出数据 - return Response::send($data, '', Config::get('response_return')); + return Response::send($data, Config::get('default_return_type'), Config::get('response_return')); } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); diff --git a/library/think/response.php b/library/think/response.php index cba81750..ecdf0bc5 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -137,11 +137,7 @@ class Response 'time' => NOW_TIME, 'data' => $data, ]; - - self::$data = $result; - if ($type) { - self::$type = $type; - } + return $result; } /** @@ -159,20 +155,16 @@ class Response 'code' => 1, 'msg' => $msg, 'data' => $data, - 'url' => $url ? $url : $_SERVER["HTTP_REFERER"], + 'url' => $url ?: $_SERVER["HTTP_REFERER"], 'wait' => $wait, ]; - $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); - if ('html' == $type) { - $view = new \think\View(); - $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); + if(IS_AJAX){ + Config::set('default_return_type', Config::get('default_ajax_return')); } - self::$data = $result; - if ($type) { - self::$type = $type; + if ('html' == Config::get('default_return_type')) { + $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result); } - self::$isExit = true; - self::send(); + return $result; } /** @@ -190,20 +182,16 @@ class Response 'code' => 0, 'msg' => $msg, 'data' => $data, - 'url' => $url ? $url : 'javascript:history.back(-1);', + 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait, ]; - $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); - if ('html' == $type) { - $view = new \think\View(); - $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); + if(IS_AJAX){ + Config::set('default_return_type', Config::get('default_ajax_return')); } - self::$data = $result; - if ($type) { - self::$type = $type; + if ('html' == Config::get('default_return_type')) { + $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result); } - self::$isExit = true; - self::send(); + return $result; } /**