#1 djfbob
public function pager($page, $pageSize = 10, $scope = 10, $total){
$this->page = null;
if($total > $pageSize){
$total_page = ceil($total / $pageSize);
$page = min(intval(max($page, 1)), $total);
$this->page = array(
'total_count' => $total,
'page_size' => $pageSize,
'total_page' => $total_page,
'first_page' => 1,
'prev_page' => ( ( 1 == $page ) ? 1 : ($page - 1) ),
'next_page' => ( ( $page == $total_page ) ? $total_page : ($page + 1)),
'last_page' => $total_page,
'current_page'=> $page,
'all_pages' => array(),
'offset' => ($page - 1) * $pageSize,
'limit' => $pageSize,
);
$scope = (int)$scope;
if($total_page <= $scope ){
$this->page['all_pages'] = range(1, $total_page);
}elseif( $page <= $scope/2) {
$this->page['all_pages'] = range(1, $scope);
}elseif( $page <= $total_page - $scope/2 ){
$right = $page + (int)($scope/2);
$this->page['all_pages'] = range($right-$scope+1, $right);
}else{
$this->page['all_pages'] = range($total_page-$scope+1, $total_page);
}
}
return $this->page;
}
2018-09-15 11:51:41