Skip to content

Commit

Permalink
模型类toCollection方法增加参数指定数据集类
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jan 19, 2018
1 parent 2912353 commit c3ba1e6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions library/think/model/concern/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ public function jsonSerialize()
* 转换数据集为数据集对象
* @access public
* @param array|Collection $collection 数据集
* @param string $resultSetType 数据集类
* @return Collection
*/
public function toCollection($collection)
public function toCollection($collection, $resultSetType = null)
{
if ($this->resultSetType && false !== strpos($this->resultSetType, '\\')) {
$class = $this->resultSetType;
$collection = new $class($collection);
$resultSetType = $resultSetType ?: $this->resultSetType;

if ($resultSetType && false !== strpos($resultSetType, '\\')) {
$collection = new $resultSetType($collection);
} else {
$collection = new ModelCollection($collection);
}
Expand Down

0 comments on commit c3ba1e6

Please sign in to comment.