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

WBOY
リリース: 2016-07-25 09:01:02
オリジナル
1357 人が閲覧しました
ページネーション クラス - 末尾のページ番号ナビゲーション
  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<=10){// 合計ページ数が以下です10 ページまで
  20. if( $this->currentPage==1){// 現在のページが最初のページです
  21. $str='前のページ'.$this->currentTag();
  22. for ($i = 2; $i < = $this->totalPage; $i++) {
  23. $str=$str.$this->commonTag($i);
  24. $str=$str.$this-> next();
  25. } elseif ($this->currentPage==$this->totalPage){//最後のページにジャンプしました
  26. $str=$this->up();
  27. for ($i = 1; $i < ;= $this->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; $i< $this-> $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 < $this->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<6) {
  62. $str=$this->up();
  63. for ($i = 1; $i < $this->currentPage; $i++) {
  64. $str=$str.$ this->commonTag($ i);
  65. }
  66. $str=$str.$this->currentTag();
  67. for ($i = $this->currentPage+1; $i $str =$str.$this->commonTag($i);
  68. }
  69. $str=$str.'...';//省略記号を追加します
  70. $str=$str.$this ->commonTag($this ->totalPage);
  71. $str=$str.$this->next();
  72. }else {
  73. if ($this->currentPage>=$this->totalPage -4) {
  74. $str =$this->up();
  75. $str=$str.$this->commonTag(1);
  76. $str=$str.'...';//追加ellipses
  77. for ($i = $this->totalPage-6; $i < $this->currentPage; $i++) {
  78. $str=$str.$this->commonTag($i);
  79. }
  80. $str=$str .$this->currentTag();
  81. for ($i = $this->currentPage+1; $i totalPage; $i++) {
  82. $ str=$str.$this ->commonTag($i);
  83. }
  84. $str=$str.$this->next();
  85. }elseif ($this->currentPage<$this-> totalPage-4){// 1+5+1
  86. $str=$this->up();
  87. $str=$str.$this->commonTag(1);
  88. $str=$str.' ...';// 省略記号を追加します
  89. $str=$str.$this->commonTag($this->currentPage-2);
  90. $str=$str.$this->commonTag($this- >currentPage-1);
  91. $str=$str.$this->currentTag();
  92. $str=$str.$this->commonTag($this->currentPage+1);
  93. $str =$str.$this- >commonTag($this->currentPage+2);
  94. $str=$str.'...';//省略記号を追加します
  95. $str=$str.$this-> commonTag($this-> totalPage);
  96. $str=$str.$this->next();
  97. }
  98. };
  99. }
  100. }elseif ($this->totalPage<=0){
  101. throw new Exception("1 未満のページは不可能です");
  102. }
  103. return $str;
  104. }
  105. /**
  106. * 一般タグ
  107. * @param int $param ページ番号
  108. * @return string
  109. */
  110. function commonTag($param) {
  111. return ''.$param.'';
  112. }
  113. /**
  114. * 現在のページラベルを生成します
  115. * @param int $param ページ番号
  116. * @return string
  117. */
  118. function currentTag() {
  119. return ''.$this->currentPage.'';
  120. }
  121. /* *
  122. * 次のページのラベルを生成します
  123. * @param int $param 次のページのページ番号
  124. * @return string
  125. */
  126. function next() {
  127. if ($this->currentPage==$this->totalPage) {
  128. return '下一页';
  129. }
  130. return '次页';
  131. }
  132. /**
  133. * 前のページのラベルを生成します
  134. * @param int $param 前のページのページ番号
  135. * @return string
  136. */
  137. function up() {
  138. if ($this- >currentPage==1){
  139. return '上一页';
  140. }else{
  141. return '上一页< ;/a>';
  142. }
  143. }
  144. /**
  145. * cmtTail をインスタンス化します,
  146. * 機能: Comment の末尾ページング ナビゲーションを生成します
  147. * @param string $currentPage 現在のページ番号
  148. * @param string $totalPage 総ページ数
  149. * @return string return HTML タグ文字列
  150. */
  151. static function GO($currentPage, $totalPage) {
  152. $p=new cmtTail();
  153. return $p->__do($ currentPage, $totalPage);
  154. }
  155. }
复制代


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!