1
2
/**
3
* filename: ext_page.class.php
4
* @package:phpbean
5
* @author :feifengxlq
6
* @copyright :Copyright 2006 feifengxlq
7
* @license:version 2.0
8
* @create:2006-5-31
9
* @modify:2006-6-1
10
* @modify:feifengxlq 2006-11-4
11
* description:超强分页类,四种分页模式,默认采用类似baidu,google的分页风格。
12
* 2.0增加功能:支持自定义风格,自定义样式,同时支持PHP4和PHP5,
13
* to see detail,please visit [url=http://www.phpobject.net/blog/read.php]http://www.phpobject.net/blog/read.php[/url]?
14
* example:
15
* 模式四种分页模式:
16
require_once('../libs/classes/page.class.php');
17
$page=new page(array('total'=>1000,'perpage'=>20));
18
echo 'mode:1
'.$page->show();
19
echo '
mode:2
'.$page->show(2);
20
echo '
mode:3
'.$page->show(3);
21
echo '
mode:4
'.$page->show(4);
22
开启AJAX:
23
$ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test'));
24
echo 'mode:1
'.$ajaxpage->show();
25
采用继承自定义分页显示模式:
26
demo:http://www.phpobject.net/blog
27
*/
28
class page
29
{
30
/**
31
* config ,public
32
*/
33
var $page_name="PB_page";//page标签,用来控制url页。比如说xxx.php?PB_page=2中的PB_page
34
var $next_page='>';//下一页
35
var $pre_page='';//上一页
36
var $first_page='First';//首页
37
var $last_page='Last';//尾页
38
var $pre_bar='';//上一分页条
39
var $next_bar='>>';//下一分页条
40
var $format_left='[';
41
var $format_right=']';
42
var $is_ajax=false;//是否支持AJAX分页模式
43
44
/**
45
* private
46
*
47
*/
48
var $pagebarnum=10;//控制记录条的个数。
49
var $totalpage=0;//总页数
50
var $ajax_action_name='';//AJAX动作名
51
var $nowindex=1;//当前页
52
var $url="";//url地址头
53
var $offset=0;
54
55
/**
56
* constructor构造函数
57
*
58
* @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']
59
*/
60
function page($array)
61
{
62
if(is_array($array)){
63
if(!array_key_exists('total',$array))$this->error(__FUNCTION__,'need a param of total');
64
$total=intval($array['total']);
65
$perpage=(array_key_exists('perpage',$array))?intval($array['perpage']):10;
66
$nowindex=(array_key_exists('nowindex',$array))?intval($array['nowindex']):'';
67
$url=(array_key_exists('url',$array))?$array['url']:'';
68
}else{
69
$total=$array;
70
$perpage=10;
71
$nowindex='';
72
$url='';
73
}
74
if((!is_int($total))||($total0))$this->error(__FUNCTION__,$total.' is not a positive integer!');
75
if((!is_int($perpage))||($perpage0))$this->error(__FUNCTION__,$perpage.' is not a positive integer!');
76
if(!empty($array['page_name']))$this->set('page_name',$array['page_name']);//设置pagename
77
$this->_set_nowindex($nowindex);//设置当前页
78
$this->_set_url($url);//设置链接地址
79
$this->totalpage=ceil($total/$perpage);
80
$this->offset=($this->nowindex-1)*$this->perpage;
81
if(!empty($array['ajax']))$this->open_ajax($array['ajax']);//打开AJAX模式
82
}
83
/**
84
* 设定类中指定变量名的值,如果改变量不属于这个类,将throw一个exception
85
*
86
* @param string $var
87
* @param string $value
88
*/
89
function set($var,$value)
90
{
91
if(in_array($var,get_object_vars($this)))
92
$this->$var=$value;
93
else {
94
$this->error(__FUNCTION__,$var." does not belong to PB_Page!");
95
}
96
97
}
98
/**
99
* 打开倒AJAX模式
100
*
101
* @param string $action 默认ajax触发的动作。
102
*/
103
function open_ajax($action)
104
{
105
$this->is_ajax=true;
106
$this->ajax_action_name=$action;
107
}
108
/**
109
* 获取显示"下一页"的代码
110
*
111
* @param string $style
112
* @return string
113
*/
114
function next_page($style='')
115
{
116
if($this->nowindex$this->totalpage){
117
return $this->_get_link($this->_get_url($this->nowindex+1),$this->next_page,$style);
118
}
119
return ''.$style.'">'.$this->next_page.'';
120
}
121
122
/**
123
* 获取显示“上一页”的代码
124
*
125
* @param string $style
126
* @return string
127
*/
128
function pre_page($style='')
129
{
130
if($this->nowindex>1){
131
return $this->_get_link($this->_get_url($this->nowindex-1),$this->pre_page,$style);
132
}
133
return ''.$style.'">'.$this->pre_page.'';
134
}
135
136
/**
137
* 获取显示“首页”的代码
138
*
139
* @return string
140
*/
141
function first_page($style='')
142
{
143
if($this->nowindex==1){
144
return ''.$style.'">'.$this->first_page.'';
145
}
146
return $this->_get_link($this->_get_url(1),$this->first_page,$style);
147
}
148
149
/**
150
* 获取显示“尾页”的代码
151
*
152
* @return string
153
*/
154
function last_page($style='')
155
{
156
if($this->nowindex==$this->totalpage){
157
return ''.$style.'">'.$this->last_page.'';
158
}
159
return $this->_get_link($this->_get_url($this->totalpage),$this->last_page,$style);
160
}
161
162
function nowbar($style='',$nowindex_style='')
163
{
164
$plus=ceil($this->pagebarnum/2);
165
if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage)$plus=($this->pagebarnum-$this->totalpage+$this->nowindex);
166

2

3

4

5


7

8

9

10

11

12

13

14

15

16

17

18

'.$page->show();
19

mode:2
'.$page->show(2);
20

mode:3
'.$page->show(3);
21

mode:4
'.$page->show(4);
22

23

24

'.$ajaxpage->show();
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

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
<🎜>:種植花園 - 完整的突變指南
3 週前ByDDD
<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前By尊渡假赌尊渡假赌尊渡假赌
如何修復KB5055612無法在Windows 10中安裝?
3 週前ByDDD
北端:融合系統,解釋
3 週前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

WebStorm Mac版
好用的JavaScript開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具