Model类增加resultSetType属性 用于指定模型查询的数据集对象(默认为空返回数组) Db类查询不再支持设置自定义数据集对象(只能使用数组或者think\Collection)

This commit is contained in:
thinkphp
2016-12-05 16:24:02 +08:00
parent 30077757bd
commit 405825ff8a
3 changed files with 23 additions and 25 deletions

View File

@@ -111,6 +111,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
protected $useGlobalScope = true;
// 是否采用批量验证
protected $batchValidate = false;
// 查询数据集对象
protected $resultSetType;
/**
* 初始化过的模型.
@@ -574,7 +576,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/
public function toCollection($collection)
{
return new Collection($collection);
if ($this->resultSetType) {
if ('collection' == $this->resultSetType) {
$collection = new Collection($collection);
} else {
$class = $this->resultSetType;
$collection = new $class($collection);
}
}
return $collection;
}
/**