分页类——尾部页码导航

WBOY
Freigeben: 2016-07-25 09:01:02
Original
1378 Leute haben es durchsucht
分页类——尾部页码导航
  1. /**
  2. * 生成Comment的尾部分页导航
  3. * @author 李俊
  4. *
  5. */
  6. class cmtTail{
  7. private $currentPage;
  8. private $totalPage;
  9. /**
  10. * 生成页码导航--总控函数
  11. * @param string $currentPage 当前页码
  12. * @param string $totalPage 总页数
  13. * @throws Exception 页码小于1将会抛出异常
  14. * @return string
  15. */
  16. function __do($currentPage, $totalPage) {
  17. $this->currentPage=$currentPage;
  18. $this->totalPage=$totalPage;
  19. if($this->totalPage if($this->currentPage==1){//当前页是第一页
  20. $str='上一页'.$this->currentTag();
  21. for ($i = 2; $i totalPage; $i++) {
  22. $str=$str.$this->commonTag($i);
  23. }
  24. $str=$str.$this->next();
  25. }elseif ($this->currentPage==$this->totalPage){//已跳至最后一页
  26. $str=$this->up();
  27. for ($i = 1; $i totalPage-1; $i++) {
  28. $str=$str.$this->commonTag($i);
  29. }
  30. $str=$str.$this->currentTag();
  31. $str=$str.$this->next();
  32. }else{
  33. $str=$this->up();
  34. for($i=1; $icurrentPage; $i++){
  35. $str=$str.$this->commonTag($i);
  36. }
  37. $str=$str.$this->currentTag();//生成当前页标签
  38. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  39. $str=$str.$this->commonTag($i);
  40. }
  41. $str=$str.$this->next();
  42. }
  43. }elseif ($this->totalPage>10){//页码大于10
  44. if($this->currentPage==1){//8+2
  45. $str='上一页'.$this->currentTag();
  46. for ($i = 2; $i $str=$str.$this->commonTag($i);
  47. }
  48. $str=$str.'...';//添加省略号
  49. $str=$str.$this->commonTag($this->totalPage-1);
  50. $str=$str.$this->commonTag($this->totalPage);
  51. }elseif($this->currentPage==$this->totalPage) {//当前为最后一页
  52. $str=$this->up();
  53. $str=$str.$this->commonTag(1);
  54. $str=$str.'...';//添加省略号
  55. for ($i = $this->totalPage-6; $i totalPage; $i++) {
  56. $str=$str.$this->commonTag($i);
  57. }
  58. $str=$str.$this->currentTag();
  59. $str=$str.$this->next();
  60. }else {
  61. if ($this->currentPage $str=$this->up();
  62. for ($i = 1; $i currentPage; $i++) {
  63. $str=$str.$this->commonTag($i);
  64. }
  65. $str=$str.$this->currentTag();
  66. for ($i = $this->currentPage+1; $i $str=$str.$this->commonTag($i);
  67. }
  68. $str=$str.'...';//添加省略号
  69. $str=$str.$this->commonTag($this->totalPage);
  70. $str=$str.$this->next();
  71. }else {
  72. if ($this->currentPage>=$this->totalPage-4) {
  73. $str=$this->up();
  74. $str=$str.$this->commonTag(1);
  75. $str=$str.'...';//添加省略号
  76. for ($i = $this->totalPage-6; $i currentPage; $i++) {
  77. $str=$str.$this->commonTag($i);
  78. }
  79. $str=$str.$this->currentTag();
  80. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  81. $str=$str.$this->commonTag($i);
  82. }
  83. $str=$str.$this->next();
  84. }elseif ($this->currentPagetotalPage-4){//1+5+1
  85. $str=$this->up();
  86. $str=$str.$this->commonTag(1);
  87. $str=$str.'...';//添加省略号
  88. $str=$str.$this->commonTag($this->currentPage-2);
  89. $str=$str.$this->commonTag($this->currentPage-1);
  90. $str=$str.$this->currentTag();
  91. $str=$str.$this->commonTag($this->currentPage+1);
  92. $str=$str.$this->commonTag($this->currentPage+2);
  93. $str=$str.'...';//添加省略号
  94. $str=$str.$this->commonTag($this->totalPage);
  95. $str=$str.$this->next();
  96. }
  97. };
  98. }
  99. }elseif ($this->totalPage throw new Exception("页面不可能小于1");
  100. }
  101. return $str;
  102. }
  103. /**
  104. * 一般标签
  105. * @param int $param 页码
  106. * @return string
  107. */
  108. function commonTag($param) {
  109. return ''.$param.'';
  110. }
  111. /**
  112. * 生成当前页标签
  113. * @param int $param 页码
  114. * @return string
  115. */
  116. function currentTag() {
  117. return ''.$this->currentPage.'';
  118. }
  119. /**
  120. * 生成下一页标签
  121. * @param int $param 下一页页码
  122. * @return string
  123. */
  124. function next() {
  125. if ($this->currentPage==$this->totalPage) {
  126. return '下一页';
  127. }
  128. return '下一页';
  129. }
  130. /**
  131. * 生成上一页标签
  132. * @param int $param 上一页页码
  133. * @return string
  134. */
  135. function up() {
  136. if ($this->currentPage==1){
  137. return '上一页';
  138. }else{
  139. return '上一页';
  140. }
  141. }
  142. /**
  143. * 实例化cmtTail,
  144. * 功能:生成Comment的尾部分页导航
  145. * @param string $currentPage 当前页码
  146. * @param string $totalPage 总页数
  147. * @return string 返回html标签字符串
  148. */
  149. static function GO($currentPage, $totalPage) {
  150. $p=new cmtTail();
  151. return $p->__do($currentPage, $totalPage);
  152. }
  153. }
复制代码


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!