From ae2824ced110087d3bf30d81a0adcfd21424d7fb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 7 Jun 2016 11:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bresponse=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E5=87=BD=E6=95=B0=20=E6=94=B9=E8=BF=9BResponse=E7=B1=BB?= =?UTF-8?q?=E7=9A=84header=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 10 +++++----- library/think/Model.php | 2 -- library/think/Response.php | 10 +++++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/helper.php b/helper.php index 18d8c86e..8e549b02 100644 --- a/helper.php +++ b/helper.php @@ -356,15 +356,15 @@ function request() } /** - * 创建Response对象实例 + * 创建普通 Response 对象实例 * @param mixed $data 输出数据 - * @param string $type 输出类型 - * @param array $options 参数 + * @param string $code 状态码 + * @param array $header 头信息 * @return Response */ -function response($data = [], $type = '', $options = []) +function response($data = [], $code = 200, $header = [], $type = 'html') { - return Response::create($data, $type, $options); + return Response::create($data, $type)->code($code)->header($header); } /** diff --git a/library/think/Model.php b/library/think/Model.php index 7f23f479..664caf3a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -321,12 +321,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = json_encode($value, JSON_FORCE_OBJECT); } break; - case 'array': $value = (array) $value; case 'json': $value = json_encode($value, JSON_UNESCAPED_UNICODE); - break; } return $value; diff --git a/library/think/Response.php b/library/think/Response.php index d3d6d7eb..1feec722 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -216,13 +216,17 @@ class Response /** * 设置响应头 * @access public - * @param string $name 参数名 + * @param string|array $name 参数名 * @param string $value 参数值 * @return $this */ - public function header($name, $value) + public function header($name, $value = null) { - $this->header[$name] = $value; + if (is_array($name)) { + $this->header = $name; + } else { + $this->header[$name] = $value; + } return $this; }