* dao: modify the condition for setting pageID in page function after adding pager offset.
This commit is contained in:
@@ -291,6 +291,34 @@ class dao extends baseDAO
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将记录进行分页,自动设置limit语句。
|
||||
* Page the records, set the limit part auto.
|
||||
*
|
||||
* @param object $pager
|
||||
* @param string $distinctField
|
||||
* @access public
|
||||
* @return static|sql the dao object self.
|
||||
*/
|
||||
public function page($pager, $distinctField = '')
|
||||
{
|
||||
if(!is_object($pager)) return $this;
|
||||
|
||||
/*
|
||||
* 重新计算分页数据,并判断是否需要返回上一页。
|
||||
* Calculate pagination to determine whether to return to the previous page.
|
||||
*/
|
||||
$originalPageID = $pager->pageID;
|
||||
$recTotal = $this->count($distinctField);
|
||||
|
||||
$pager->setRecTotal($recTotal);
|
||||
$pager->setPageTotal();
|
||||
if($originalPageID > ceil(($pager->recTotal - $pager->offset) / $pager->recPerPage)) $pager->setPageID($pager->pageTotal);
|
||||
|
||||
$this->sqlobj->limit($pager->limit());
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user