mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
Model类增加toJson方法输出JSON字符串
This commit is contained in:
@@ -169,6 +169,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return !empty($item) ? $item : [];
|
return !empty($item) ? $item : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换当前模型对象为JSON字符串
|
||||||
|
* @access public
|
||||||
|
* @param integer $options json参数
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function toJson($options = JSON_UNESCAPED_UNICODE)
|
||||||
|
{
|
||||||
|
return json_encode($this->toArray(), $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前模型对象的主键
|
* 获取当前模型对象的主键
|
||||||
* @access public
|
* @access public
|
||||||
@@ -980,7 +991,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return json_encode($this->toArray());
|
return $this->toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsonSerializable
|
// JsonSerializable
|
||||||
|
|||||||
Reference in New Issue
Block a user