thinkPHP架構可添加js事件的分頁類完整範例程式碼

來源:互聯網
上載者:User
這篇文章主要介紹了thinkPHP架構可添加js事件的分頁類customPage.class.php,以完整執行個體形式給出了分頁類customPage.class.php的實現代碼並分析了ajax動態載入資料,設定分頁連結等功能,需要的朋友可以參考下

本文執行個體講述了thinkPHP架構可添加js事件的分頁類customPage.class.php。分享給大家供大家參考,具體如下:

用於ajax動態載入資料的分頁類,分頁事件可以動態添加,去除了a連結中的href地址。


<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: 麥當苗兒 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>// +----------------------------------------------------------------------namespace Think;class customPage{  public $firstRow; // 起始行數  public $listRows; // 列表每頁顯示行數  public $parameter; // 分頁跳轉時要帶的參數  public $totalRows; // 總行數  public $totalPages; // 分頁總頁面數  public $rollPage  = 6;// 分頁欄每頁顯示的頁數  public $lastSuffix = true; // 最後一頁是否顯示總頁數  private $p    = 'p'; //分頁參數名  private $url   = ''; //當前連結URL  private $nowPage = 1;  // 分頁顯示定製  private $config = array(    'header' => '<span class="rows">共 %TOTAL_ROW% 條記錄</span>',    'prev'  => '上一頁',    'next'  => '下一頁',    'first' => '1...',    'last'  => '...%TOTAL_PAGE%',    'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',  );  /**   * 架構函數   * @param array $totalRows 總的記錄數   * @param array $listRows 每頁顯示記錄數   * @param array $parameter 分頁跳轉的參數   */  public function construct($totalRows, $listRows=20, $parameter = array()) {    C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //設定分頁參數名稱    /* 基礎設定 */    $this->totalRows = $totalRows; //設定總記錄數    $this->listRows  = $listRows; //設定每頁顯示行數    $this->parameter = empty($parameter) ? $_GET : $parameter;    $this->nowPage  = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);    $this->totalPages = ceil($this->totalRows / $this->listRows); //總頁數    if ($this->nowPage>$this->totalPages) {      $this->nowPage = $this->totalPages ;    }    $this->nowPage  = $this->nowPage>0 ? $this->nowPage : 1;    $this->firstRow  = $this->listRows * ($this->nowPage - 1);  }  /**   * 定製分頁連結設定   * @param string $name 設定名稱   * @param string $value 設定值   */  public function setConfig($name,$value) {    if(isset($this->config[$name])) {      $this->config[$name] = $value;    }  }  /**   * 產生連結URL   * @param integer $page 頁碼   * @return string   */  private function url($page){    return str_replace(urlencode('[PAGE]'), $page, $this->url);  }  /**   * 組裝分頁連結   * @return string   */  public function show() {    if(0 == $this->totalRows) return '';    /* 產生URL */    $this->parameter[$this->p] = '[PAGE]';    $this->url = U(ACTION_NAME, $this->parameter);    /* 計算分頁資訊 */    if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) {      $this->nowPage = $this->totalPages;    }    /* 計算分頁臨時變數 */    $now_cool_page   = $this->rollPage/2;    $now_cool_page_ceil = ceil($now_cool_page);    $this->lastSuffix && $this->config['last'] = $this->totalPages;    //上一頁    $up_row = $this->nowPage - 1;    $up_page = $up_row > 0 ? '<a class="shang" id="'.$up_row.'"href="javascript:;" rel="external     nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >上一頁</a>' : '';    //下一頁    $down_row = $this->nowPage + 1;    $down_page = ($down_row <= $this->totalPages) ? '<a class="xia" id="'.$down_row.'" href="javascript:;"     rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下一頁</a>' : '';    //第一頁    $the_first = '';    if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){      $the_first = '<a class="first" id="1" href="javascript:;" rel="external nofollow"       rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >第一頁</a>';    }    //最後一頁    $the_end = '';    //if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){    if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){      $the_end = '<a class="end" id="'.$this->totalRows.'" href="javascript:;"       rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最後一頁</a>';    }    for($i = 1; $i <= $this->rollPage; $i++){        if(($this->nowPage - $now_cool_page) <= 0 ){          $page = $i;        }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){          $page = $this->totalPages - $this->rollPage + $i;        }else{          $page = $this->nowPage - $now_cool_page_ceil + $i;        }        if($page > 0 && $page != $this->nowPage){          if($page <= $this->totalPages){            $link_page .= ('<li id="'.$page.'">'.$page.'</li>');          }else{            break;          }        }else{          if($page > 0 && $this->totalPages != 1){            $link_page .= ('<li id="now" id="'.$page.'" class="current">'.$page.'</li>');          }        }    }    if (!empty($link_page)) $link_page = '<ul id="list">'.$link_page.'</ul>';    //替換分頁內容    $page_str = str_replace(      array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'),      array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),      $this->config['theme']);    $page_str = trim($page_str);    if(!empty($page_str)) $page_str .= '<p></p>    <input value="" type="text">    <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external     nofollow" rel="external nofollow" rel="external nofollow" id="go" class="go">跳轉</a>';    return $page_str;  }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.