From e5740e545117c1dd0ac63616959206f37134cbac Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 16 Jun 2016 11:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB=E7=9A=84run?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9BResponse=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 6 ++++-- library/think/Response.php | 13 +++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index b6e28404..61ef4808 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -128,11 +128,13 @@ class App // 输出数据到客户端 if ($data instanceof Response) { return $data; - } else { + } elseif(!is_null($data)) { // 默认自动识别响应输出类型 $isAjax = $request->isAjax(); $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); - return Response::create( is_null($data) ? '' : $data, $type); + return Response::create($data, $type); + } else { + return Response::create(); } } diff --git a/library/think/Response.php b/library/think/Response.php index c986e5a8..2a2c7067 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -51,15 +51,12 @@ class Response public function __construct($data = [], $type = '', $options = []) { $this->data = $data; - if (empty($type)) { - $isAjax = Request::instance()->isAjax(); - $type = $isAjax ? 'json' : 'html'; - } - $this->type = strtolower($type); + $this->type = empty($type) ? 'null' : strtolower($type); if (isset($this->contentTypes[$this->type])) { $this->contentType($this->contentTypes[$this->type]); } + if (!empty($options)) { $this->options = array_merge($this->options, $options); } @@ -77,11 +74,7 @@ class Response */ public static function create($data = [], $type = '', $options = []) { - if (empty($type)) { - $isAjax = Request::instance()->isAjax(); - $type = $isAjax ? 'json' : 'html'; - } - $type = strtolower($type); + $type = empty($type) ? 'null' : strtolower($type); if (!isset(self::$instance[$type])) { $class = (isset($options['namespace']) ? $options['namespace'] : '\\think\\response\\') . ucfirst($type);