#1 冈刀飞絮
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);
}else{
$this->page['all_pages'] = range($page - $scope/2 , min( $page + $scope/2 -1, $total_page));
}
}
return $this->page;
}
半径前半大后半小。
再附加一个使用分页的列子:
Action:
$page = isset($_GET["page"])? $_GET['page']:1 ;模板:
$my = new My();
$oo = $my->findAll("","id desc","*", array($page, 20));
$this->page = $my->page;
$this->mydd = $oo;
$this->display("test.html");
| <{$v.id}> | <{$v.name}> |
总数量:<{$page.total_count}> 总页数:<{$page.total_page}> 页码 <{foreach $page.all_pages as $p}> <{if $p== $page.current_page}> <{$p}> <{else}> <{$p}> <{/if}> <{/foreach}> | |
2015-10-18 15:15:02