ホームページ >バックエンド開発 >PHPチュートリアル >ページネーション クラス - 末尾のページ番号ナビゲーション

ページネーション クラス - 末尾のページ番号ナビゲーション

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2016-07-25 09:01:021534ブラウズ
ページネーション クラス - 末尾のページ番号ナビゲーション
  1. /**
  2. * コメントの末尾ページング ナビゲーションを生成します
  3. * @author Li Jun
  4. *
  5. */
  6. class cmtTail{
  7. private $currentPage;
  8. private $totalPage;
  9. /**
  10. * ページ番号ナビゲーションの生成 - トータルコントロール関数
  11. * @param string $currentPage 現在のページ番号
  12. * @param string $totalPage 合計ページ番号
  13. * @throws 例外 ページ番号が 1 未満の場合、例外がスローされます
  14. * @return 文字列
  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. $str=$str.$this-> next();
  24. } elseif ($this->currentPage==$this->totalPage){//最後のページにジャンプしました
  25. $str=$this->up();
  26. for ($i = 1; $i < ;= $this->totalPage-1; $i++) {
  27. $str=$str.$this->commonTag($i);
  28. }
  29. $str=$str.$this- >currentTag() ;
  30. $str=$str.$this->next();
  31. }else{
  32. $str=$this->up();
  33. for($i=1; $i $i++){
  34. $str=$str.$this->commonTag($i);
  35. }
  36. $str=$str.$this->currentTag();//生成現在のページタグ
  37. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  38. $str=$str.$this->commonTag($ i);
  39. }
  40. $str=$str.$this->next();
  41. }
  42. }elseif ($this->totalPage>10){//ページ番号が 10 より大きいです
  43. if($ this->currentPage==1){ //8+2
  44. $str='前のページ'.$this->currentTag();
  45. for ($i = 2; $i $str=$str. $this->commonTag($i);
  46. }
  47. $str=$str.'...';// 省略記号を追加します
  48. $str=$str.$this-> ;commonTag($this->totalPage -1);
  49. $str=$str.$this->commonTag($this->totalPage);
  50. }elseif($this->currentPage==$this- >totalPage) {//現在の最後のページ
  51. $str=$this->up();
  52. $str=$str.$this->commonTag(1);
  53. $str=$str.'.. .';//省略記号
  54. を追加 for ($i = $this->totalPage-6; $i totalPage; $i++) {
  55. $str=$str.$this->commonTag ($i);
  56. }
  57. $str=$str.$this->currentTag();
  58. $str=$str.$this->next();
  59. }else {
  60. if ($this-> ;currentPage $str=$this->up();
  61. for ($i = 1; $i currentPage; $i++) {
  62. $str=$str.$ this->commonTag($ i);
  63. }
  64. $str=$str.$this->currentTag();
  65. for ($i = $this->currentPage+1; $i $str =$str.$this->commonTag($i);
  66. }
  67. $str=$str.'...';//省略記号を追加します
  68. $str=$str.$this ->commonTag($this ->totalPage);
  69. $str=$str.$this->next();
  70. }else {
  71. if ($this->currentPage>=$this->totalPage -4) {
  72. $str =$this->up();
  73. $str=$str.$this->commonTag(1);
  74. $str=$str.'...';//追加ellipses
  75. for ($i = $this->totalPage-6; $i currentPage; $i++) {
  76. $str=$str.$this->commonTag($i);
  77. }
  78. $str=$str .$this->currentTag();
  79. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  80. $ str=$str.$this ->commonTag($i);
  81. }
  82. $str=$str.$this->next();
  83. }elseif ($this->currentPage totalPage-4){// 1+5+1
  84. $str=$this->up();
  85. $str=$str.$this->commonTag(1);
  86. $str=$str.' ...';// 省略記号を追加します
  87. $str=$str.$this->commonTag($this->currentPage-2);
  88. $str=$str.$this->commonTag($this- >currentPage-1);
  89. $str=$str.$this->currentTag();
  90. $str=$str.$this->commonTag($this->currentPage+1);
  91. $str =$str.$this- >commonTag($this->currentPage+2);
  92. $str=$str.'...';//省略記号を追加します
  93. $str=$str.$this-> commonTag($this-> totalPage);
  94. $str=$str.$this->next();
  95. }
  96. };
  97. }
  98. }elseif ($this->totalPage throw new Exception("1 未満のページは不可能です");
  99. }
  100. return $str;
  101. }
  102. /**
  103. * 一般タグ
  104. * @param int $param ページ番号
  105. * @return string
  106. */
  107. function commonTag($param) {
  108. return ''.$param.'';
  109. }
  110. /**
  111. * 現在のページラベルを生成します
  112. * @param int $param ページ番号
  113. * @return string
  114. */
  115. function currentTag() {
  116. return ''.$this->currentPage.'';
  117. }
  118. /* *
  119. * 次のページのラベルを生成します
  120. * @param int $param 次のページのページ番号
  121. * @return string
  122. */
  123. function next() {
  124. if ($this->currentPage==$this->totalPage) {
  125. return '下一页';
  126. }
  127. return '次页';
  128. }
  129. /**
  130. * 前のページのラベルを生成します
  131. * @param int $param 前のページのページ番号
  132. * @return string
  133. */
  134. function up() {
  135. if ($this- >currentPage==1){
  136. return '上一页';
  137. }else{
  138. return '上一页< ;/a>';
  139. }
  140. }
  141. /**
  142. * cmtTail をインスタンス化します,
  143. * 機能: Comment の末尾ページング ナビゲーションを生成します
  144. * @param string $currentPage 現在のページ番号
  145. * @param string $totalPage 総ページ数
  146. * @return string return HTML タグ文字列
  147. */
  148. static function GO($currentPage, $totalPage) {
  149. $p=new cmtTail();
  150. return $p->__do($ currentPage, $totalPage);
  151. }
  152. }
复制代


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。