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脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前By尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
2 周前ByDDD
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3汉化版
中文版,非常好用

Atom编辑器mac版下载
最流行的的开源编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

禅工作室 13.0.1
功能强大的PHP集成开发环境

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中