mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进response助手函数 改进Response类的header方法 支持批量设置
This commit is contained in:
10
helper.php
10
helper.php
@@ -356,15 +356,15 @@ function request()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Response对象实例
|
* 创建普通 Response 对象实例
|
||||||
* @param mixed $data 输出数据
|
* @param mixed $data 输出数据
|
||||||
* @param string $type 输出类型
|
* @param string $code 状态码
|
||||||
* @param array $options 参数
|
* @param array $header 头信息
|
||||||
* @return Response
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -321,12 +321,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$value = json_encode($value, JSON_FORCE_OBJECT);
|
$value = json_encode($value, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'array':
|
case 'array':
|
||||||
$value = (array) $value;
|
$value = (array) $value;
|
||||||
case 'json':
|
case 'json':
|
||||||
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
|
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
|
|||||||
@@ -216,13 +216,17 @@ class Response
|
|||||||
/**
|
/**
|
||||||
* 设置响应头
|
* 设置响应头
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $name 参数名
|
* @param string|array $name 参数名
|
||||||
* @param string $value 参数值
|
* @param string $value 参数值
|
||||||
* @return $this
|
* @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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user