PHP ページング クラス コード。複数のスタイルをサポートし、ページング メソッドを設定できます。

WBOY
リリース: 2016-07-25 08:52:39
オリジナル
990 人が閲覧しました
  1. class Page {

  2. private $total;//合計数量
  3. private $limit;//mysql
  4. privateのlimit文を返す$pageStart;//開始値
  5. private $pageStop;//終了値
  6. private $pageNumber;//ページング番号の数を表示
  7. private $page;//現在のページ
  8. private $pageSize;//各ページに表示される番号
  9. private $pageToatl;//ページング
  10. private $pageParam;//ページング変数
  11. private $uri;//URL パラメータ
  12. /**
  13. * ページング設定スタイルでは大文字と小文字は区別されません
  14. * %pageToatl% //総ページ数
  15. * %page%//現在のページ
  16. * %pageSize% //現在のページに表示されるデータ項目の数
  17. * % pageStart%//このページの開始番号
  18. * %pageStop%//このページの終了番号
  19. * %total%//データ総数
  20. * %first%//ホームページ
  21. * %ending%//最後のページ
  22. * %up%/ /前のページ
  23. * %down%//次のページ
  24. * %F%//開始ページ
  25. * %E%//終了ページ
  26. * %omitFA%//前を省略してジャンプ
  27. * %omitEA % //後を省略してジャンプ
  28. * %omitF%//前を省略
  29. * %omitE%//後を省略
  30. * %numberF%//番号のページネーションの数を固定
  31. * %numberD%//左右の番号のページネーションを均等にする
  32. * %input%//ジャンプ入力ボックス
  33. * %GoTo%//ジャンプボタン
  34. */ bbs.it-home.org
  35. private $pageType = ' ページ %page%/Total%pageToatl%%first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%';
  36. / /表示値設定
  37. private $pageShow = array('first'=>'ホームページ','ending'=>'最後のページ','up'=>'前ページ','down'=> '次のページ','GoTo'=>'GO');

  38. /**

  39. * 初期化データ、構築方法
  40. * @access public
  41. * @param int $total データ総数
  42. * @param int $pageSize 各ページに表示される項目数
  43. * @param int $pageNumber ページング数表示される数値 (%numberF% を使用します。%numberD% を使用する場合とは異なる効果があります)
  44. * @param string $pageParam ページング変数
  45. * @return void
  46. */
  47. public function __construct($total,$pageSize=10,$pageNumber = 5,$pageParam='p'){
  48. $this->total = $total$this->pageSize = $pageSize$this - >pageNumber = $pageNumber<0?0:$pageNumber;
  49. $this->pageParam = $pageParam;
  50. $this->calculate();
  51. }

  52. /* *

  53. * ページネーションを表示する
  54. * @access public
  55. * @return string HTML ページネーション文字列
  56. */
  57. public function pageShow(){
  58. $this->uri();
  59. if($this->pageToatl>1){
  60. if($this->page == 1){
  61. $first = ''.$this->pageShow['first'].'';
  62. $up = 'pageShow['up'].'';
  63. }else{
  64. $first = ''.$this->pageShow['first'].'';
  65. $up = ''.$this->pageShow['up'] 。 '';
  66. }
  67. if($this->page >= $this->pageToatl){
  68. $ending = ''.$this - >pageShow['ending'].'';
  69. $down = ''.$this->pageShow['down'].'< span>';
  70. }else{
  71. $ending = ''.$this->pageShow['ending'].'';
  72. $down = ''.$this->pageShow['down'].'';
  73. }
  74. $input = '';
  75. $GoTo = '';
  76. }else{
  77. $first = ''; $ up ='';$ending = '';$down = '';$input = '';$GoTo = '';
  78. }
  79. $this->numberF();
  80. return str_ireplace(array('%pageToatl%','%page%','%pageSize%','%pageStart%','%pageStop%','%total% ','%first%','%ending%','%up%','%down%','%input%','%GoTo%'),array($this->pageToatl,$this ->ページ,$this->pageStop-$this->pageStart,$this->pageStart,$this->pageStop,$this->total,$first,$ending,$up,$ down,$input,$GoTo),$this->pageType);
  81. }

  82. /**

  83. *番号ページネーション
  84. */
  85. プライベート関数numberF(){
  86. $pageF =tripos( $this->pageType,'%numberF%');
  87. $pageD =tripos($this->pageType,'%numberD%');
  88. $numberF = '';$numberD = '';$F = '';$E ='';$omitF = '';$omitFA = '';$omitE = '';$omitEA = '';
  89. if($pageF!==false || $pageD!==false ){
  90. if($pageF!==false){
  91. $number = $this->pageNumber%2==0?$this->pageNumber/2:($this->pageNumber+1)/2 ;
  92. $DStart = $this->page - $numberpage - $number-1:0;
  93. if($this->page+$number-$DStart > $this- >pageToatl){
  94. $DStop = ($this->page+$number-$DStart) - $this->pageToatl;
  95. $forStop = $this->pageToatl+1;
  96. }else{
  97. $DStop = 0;
  98. $forStop = $this->page+$number-$DStart+1;
  99. }
  100. $forStart = $this->page-$number-$DStoppage -$number-$DStop;
  101. for($i=$forStart;$i<$forStop;++$i){
  102. if($i==$this->page){
  103. $numberF .= '< ;span class="current">'.$i.'';
  104. }else{
  105. $numberF .= ''.$i.'';
  106. }
  107. }
  108. }
  109. if($pageD!==false){
  110. $number = $this->pageNumber;
  111. $forStart = $this->page-$number>0?$this->page-$number:1;
  112. $forStop = $this->page+$number> ;$this->pageToatl?$this->pageToatl+1:$this->page+$number+1;
  113. for($i=$forStart;$ipage;++$ i){
  114. $numberD .= ''.$i .'';
  115. }
  116. $numberD .= ''.$this->page.'';
  117. $start = $this ->page+1;
  118. for($i=$start;$i<$forStop;++$i){
  119. $numberD .= ''.$i.'';
  120. }
  121. }
  122. $F = $forStart>1?'< a href="'.$this->uri.'&'.$this->pageParam.'=1">1':'';
  123. $E = $forStop<$this- >pageToatl+1?''。 $this->pageToatl.'':'';
  124. if($forStart>2){
  125. $omitF = '';
  126. $startA = $this->page-$number<1?1:$this->page-$number;
  127. $omitFA = '';
  128. }
  129. if($forStop<$this->pageToatl){
  130. $omitE = '';
  131. $stopA = $this->page+$number>$this->pageToatl?$this->pageToatl:$ this->page+$number;
  132. $omitEA = '';
  133. }
  134. }
  135. $this->pageType = str_ireplace(array('%F%','%E%','%omitFA%','%omitEA %','%omitF%','%omitE%','%numberF%','%numberD%'),array($F,$E,$omitFA,$omitEA,$omitF,$omitE,$numberF ,$numberD),$this->pageType);
  136. }

  137. /**

  138. *URL を処理するメソッド
  139. * @access public
  140. * @param array $url URL をリレーションシップ配列に直接保持します
  141. * @return フィルタリングされた文字列 URL 末尾パラメータ
  142. */
  143. プライベート関数 uri(){
  144. $url = $_SERVER["REQUEST_URI" ];
  145. $par = parse_url($url);
  146. if (isset($par['query'])) {
  147. parse_str($par['query'],$query);
  148. if(!is_array($this ->uri)){
  149. $this->uri = array();
  150. }
  151. array_merge($query,$this->uri);
  152. unset($query[$this->pageParam]);
  153. while($key = array_search('',$query)){
  154. unset($query[$key]);
  155. }
  156. $this->uri = $par['path'].'?'.http_build_query ($query);
  157. }else{
  158. $this->uri = $par['path'].'?';
  159. }
  160. }

  161. /**

  162. * 制限方法を設定し、開始番号と終了番号を計算します
  163. */
  164. プライベート関数計算(){
  165. $this->pageToatl = ceil($this->total/$this->pageSize);
  166. $this->page = intval($_GET[$this->pageParam]);
  167. $this->page = $this->page>=1?$this->page>$this- >pageToatl?$this->pageToatl:$this->page:1;
  168. $this->pageStart = ($this->page-1)*$this->pageSize;
  169. $this- >pageStop = $this->pageStart+$this->pageSize;
  170. $this->pageStop = $this->pageStop>$this->total?$this->total:$this-> ;pageStop;
  171. $this->limit = $this->pageStart.','.$this->pageStop;
  172. }

  173. /**

  174. * フィルターを設定します
  175. */
  176. public function __set($name,$value){
  177. switch($name){
  178. case 'pageType':
  179. case 'uri':
  180. $this->$name = $value;
  181. return;
  182. case 'pageShow' :
  183. if(is_array($value)){
  184. $this->pageShow = array_merge($this->pageShow,$value);
  185. }
  186. return;
  187. }
  188. }

  189. * 値フィルター
  190. */
  191. public function __get($name){
  192. switch($name){
  193. case 'limit':
  194. case 'pageStart':
  195. case 'pageStop':
  196. return $this-> $name;
  197. default:
  198. return;
  199. }
  200. }
  201. }

复制發


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