-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.php
173 lines (165 loc) · 6.27 KB
/
Page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
namespace Util;
class Page {
// 分页栏每页显示的页数
public $rollPage = 5;
// 页数跳转时要带的参数
public $parameter ;
// 分页URL地址
public $url = '';
// 默认列表每页显示行数
public $listRows = 20;
// 起始行数
public $firstRow ;
// 分页总页面数
protected $totalPages ;
// 总行数
protected $totalRows ;
// 当前页数
protected $nowPage ;
// 分页的栏的总页数
protected $coolPages ;
// 分页显示定制
protected $config = array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'最后一页','theme'=>' %nowPage%/%totalPage%页 %upPage% %linkPage% %downPage% %first% %prePage% %nextPage% %end% %totalRow%%header%');
// 默认分页变量名
protected $varPage = 'p';
/**
* 架构函数
* @access public
* @param array $totalRows 总的记录数
* @param array $listRows 每页显示记录数
* @param array $parameter 分页跳转的参数
*/
public function __construct($totalRows, $listRows='', $p = 1) {
$this->totalRows = $totalRows;
if(!empty($listRows)) {
$this->listRows = intval($listRows);
}
$this->totalPages = ceil($this->totalRows/$this->listRows); //总页数
$this->coolPages = ceil($this->totalPages/$this->rollPage);
$this->nowPage = $p;
if($this->nowPage<1){
$this->nowPage = 1;
}elseif(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {
$this->nowPage = $this->totalPages;
}
$this->firstRow = $this->listRows*($this->nowPage-1);
}
public function getPage()
{
$count = intval($this->totalRows);
$total = intval($this->totalPages);
$now = intval($this->nowPage);
$roll = intval($this->rollPage);
if ($roll == 0)
$roll = 5;
$page = array();
$page['size'] = intval($this->listRows);
$page['count'] = $count;
$page['total'] = $total;
$page['now'] = $now;
$page['prev'] = $now < 2 ? 0 : $now - 1;
$page['next'] = $now < $total ? $now + 1 : 0;
if ($roll > $total)
$roll = $total;
$roll1 = intval(ceil($roll/2));
$page['up'] = $now-$roll > 0 ? $now-$roll : 1;
$page['down'] = $now+$roll < $total ? $now+$roll : $total;
if ($now < $roll1) {
$j = 0;
} else {
$j = $now + $roll1 <= $total ? $now - $roll1 : $total - $roll;
}
$page['list'] = array();
for ($i = 0; $i < $roll; $i ++) {
++ $j;
if ($j > $total)
break;
$page['list'][] = $j;
}
return $page;
}
/**
* 分页显示输出
* @access public
*/
/*
public function show() {
if(0 == $this->totalRows) return '';
$p = $this->varPage;
$nowCoolPage = ceil($this->nowPage/$this->rollPage);
// 分析分页参数
if($this->url){
//$depr = C('URL_PATHINFO_DEPR');
//$url = rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';
}else{
if($this->parameter && is_string($this->parameter)) {
parse_str($this->parameter,$parameter);
}elseif(is_array($this->parameter)){
$parameter = $this->parameter;
}elseif(empty($this->parameter)){
unset($_GET['p']);
$var = !empty($_POST)?$_POST:$_GET;
if(empty($var)) {
$parameter = array();
}else{
$parameter = $var;
}
}
$parameter[$p] = '__PAGE__';
$url = '';
}
//上下翻页字符串
$upRow = $this->nowPage-1;
$downRow = $this->nowPage+1;
if ($upRow>0){
$upPage = "<a href='".str_replace('__PAGE__',$upRow,$url)."'>".$this->config['prev']."</a>";
}else{
$upPage = '';
}
if ($downRow <= $this->totalPages){
$downPage = "<a href='".str_replace('__PAGE__',$downRow,$url)."'>".$this->config['next']."</a>";
}else{
$downPage = '';
}
// << < > >>
if($nowCoolPage == 1){
$theFirst = '';
$prePage = '';
}else{
$preRow = $this->nowPage-$this->rollPage;
$prePage = "<a href='".str_replace('__PAGE__',$preRow,$url)."' >上".$this->rollPage."页</a>";
$theFirst = "<a href='".str_replace('__PAGE__',1,$url)."' >".$this->config['first']."</a>";
}
if($nowCoolPage == $this->coolPages){
$nextPage = '';
$theEnd = '';
}else{
$nextRow = $this->nowPage+$this->rollPage;
$theEndRow = $this->totalPages;
$nextPage = "<a href='".str_replace('__PAGE__',$nextRow,$url)."' >下".$this->rollPage."页</a>";
$theEnd = "<a href='".str_replace('__PAGE__',$theEndRow,$url)."' >".$this->config['last']."</a>";
}
// 1 2 3 4 5
$linkPage = "";
for($i=1;$i<=$this->rollPage;$i++){
$page = ($nowCoolPage-1)*$this->rollPage+$i;
if($page!=$this->nowPage){
if($page<=$this->totalPages){
$linkPage .= "<a href='".str_replace('__PAGE__',$page,$page)."'>".$page."</a>";
}else{
break;
}
}else{
if($this->totalPages != 1){
$linkPage .= "<span class='current'>".$page."</span>";
}
}
}
$pageStr = str_replace(
array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),
array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);
return $pageStr;
}
*/
}