分頁類修改內(nèi)容:只涉及到樣子生成部分代碼,在原來每個A鏈接前加了li,在返回的樣式字符串前加UL,以適合Boostrap的css文件的定義。
Bootstrap的css文件基本保持原狀,只是加了一個#lastspan的樣式定義。--------------------------------------------------------------------------------
pagination.css
- .pagination {
- margin: 20px 0;
- }
- .pagination ul {
- display: inline-block;
- list-style:none;
- *display: inline;
- /* IE7 inline-block hack */
- *zoom: 1;
- margin-left: 0;
- margin-bottom: 0;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- border-radius: 4px;
- -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
- -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
- }
- .pagination ul > li {
- display: inline;
- }
- .pagination ul > li > a,
- .pagination ul > li > span,
- .pagination #lastspan {
- float: left;
- padding: 4px 12px;
- line-height: 20px;
- text-decoration: none;
- background-color: #ffffff;
- border: 1px solid #dddddd;
- border-left-width: 0;
- }
- .pagination ul > li > a:hover,
- .pagination ul > li > a:focus,
- .pagination ul > .active > a,
- .pagination ul > .active > span {
- background-color: #f5f5f5;
- }
- .pagination ul > .active > a,
- .pagination ul > .active > span {
- color: #999999;
- cursor: default;
- }
- .pagination ul > .disabled > span,
- .pagination ul > .disabled > a,
- .pagination ul > .disabled > a:hover,
- .pagination ul > .disabled > a:focus {
- color: #999999;
- background-color: transparent;
- cursor: default;
- }
- .pagination ul > li:first-child > a,
- .pagination ul > li:first-child > span {
- border-left-width: 1px;
- -webkit-border-top-left-radius: 4px;
- -moz-border-radius-topleft: 4px;
- border-top-left-radius: 4px;
- -webkit-border-bottom-left-radius: 4px;
- -moz-border-radius-bottomleft: 4px;
- border-bottom-left-radius: 4px;
- }
- .pagination ul > li:last-child > a,
- .pagination ul > li:last-child > span,
- .pagination #lastspan {
- -webkit-border-top-right-radius: 4px;
- -moz-border-radius-topright: 4px;
- border-top-right-radius: 4px;
- -webkit-border-bottom-right-radius: 4px;
- -moz-border-radius-bottomright: 4px;
- border-bottom-right-radius: 4px;
- }
- .pagination-centered {
- text-align: center;
- }
- .pagination-right {
- text-align: right;
- }
- .pagination-large ul > li > a,
- .pagination-large ul > li > span,
- .pagination-large #lastspan{
- padding: 11px 19px;
- font-size: 17.5px;
- }
- .pagination-large ul > li:first-child > a,
- .pagination-large ul > li:first-child > span {
- -webkit-border-top-left-radius: 6px;
- -moz-border-radius-topleft: 6px;
- border-top-left-radius: 6px;
- -webkit-border-bottom-left-radius: 6px;
- -moz-border-radius-bottomleft: 6px;
- border-bottom-left-radius: 6px;
- }
- .pagination-large ul > li:last-child > a,
- .pagination-large ul > li:last-child > span,
- .pagination-large #lastspan {
- -webkit-border-top-right-radius: 6px;
- -moz-border-radius-topright: 6px;
- border-top-right-radius: 6px;
- -webkit-border-bottom-right-radius: 6px;
- -moz-border-radius-bottomright: 6px;
- border-bottom-right-radius: 6px;
- }
- .pagination-mini ul > li:first-child > a,
- .pagination-small ul > li:first-child > a,
- .pagination-mini ul > li:first-child > span,
- .pagination-small ul > li:first-child > span {
- -webkit-border-top-left-radius: 3px;
- -moz-border-radius-topleft: 3px;
- border-top-left-radius: 3px;
- -webkit-border-bottom-left-radius: 3px;
- -moz-border-radius-bottomleft: 3px;
- border-bottom-left-radius: 3px;
- }
- .pagination-mini ul > li:last-child > a,
- .pagination-small ul > li:last-child > a,
- .pagination-mini ul > li:last-child > span,
- .pagination-small ul > li:last-child > span {
- -webkit-border-top-right-radius: 3px;
- -moz-border-radius-topright: 3px;
- border-top-right-radius: 3px;
- -webkit-border-bottom-right-radius: 3px;
- -moz-border-radius-bottomright: 3px;
- border-bottom-right-radius: 3px;
- }
- .pagination-small ul > li > a,
- .pagination-small ul > li > span {
- padding: 2px 10px;
- font-size: 11.9px;
- }
- .pagination-mini ul > li > a,
- .pagination-mini ul > li > span {
- padding: 0 6px;
- font-size: 10.5px;
- }
-------------------------------------------------------------------------------
Page.class.php
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: liu21st <liu21st@gmail.com>
- // | lanfengye <zibin_5257@163.com>
- // +----------------------------------------------------------------------
- class Page {
- // 分頁欄每頁顯示的頁數(shù)
- public $rollPage = 5;
- // 頁數(shù)跳轉(zhuǎn)時要帶的參數(shù)
- public $parameter ;
- // 分頁URL地址
- public $url = '';
- // 默認(rèn)列表每頁顯示行數(shù)
- public $listRows = 20;
- // 起始行數(shù)
- public $firstRow ;
- // 分頁總頁面數(shù)
- protected $totalPages ;
- // 總行數(shù)
- protected $totalRows ;
- // 當(dāng)前頁數(shù)
- protected $nowPage ;
- // 分頁的欄的總頁數(shù)
- protected $coolPages ;
- // 分頁顯示定制
- protected $config = array('header'=>'條記錄','prev'=>'上一頁','next'=>'下一頁','first'=>'第一頁','last'=>'<span id="lastspan">最后一頁</span>','theme'=>'<ul><li><span> %totalRow% %header% %nowPage%/%totalPage% 頁</span></li> %first% %upPage% %prePage% %linkPage% %downPage% %nextPage% %end%</ul>');
- // 默認(rèn)分頁變量名
- protected $varPage;
- /**
- * 架構(gòu)函數(shù)
- * @access public
- * @param array $totalRows 總的記錄數(shù)
- * @param array $listRows 每頁顯示記錄數(shù)
- * @param array $parameter 分頁跳轉(zhuǎn)的參數(shù)
- */
- public function __construct($totalRows,$listRows='',$parameter='',$url='') {
- $this->totalRows = $totalRows;
- $this->parameter = $parameter;
- $this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ;
- if(!empty($listRows)) {
- $this->listRows = intval($listRows);
- }
- $this->totalPages = ceil($this->totalRows/$this->listRows); //總頁數(shù)
- $this->coolPages = ceil($this->totalPages/$this->rollPage);
- $this->nowPage = !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1;
- if($this->nowPage<1){
- $this->nowPage = 1;
- }elseif(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {
- $this->nowPage = $this->totalPages;
- }
- $this->firstRow = $this->listRows*($this->nowPage-1);
- if(!empty($url)) $this->url = $url;
- }
- public function setConfig($name,$value) {
- if(isset($this->config[$name])) {
- $this->config[$name] = $value;
- }
- }
- /**
- * 分頁顯示輸出
- * @access public
- */
- public function show() {
- if(0 == $this->totalRows) return '';
- $p = $this->varPage;
- $nowCoolPage = ceil($this->nowPage/$this->rollPage);
- // 分析分頁參數(shù)
- if($this->url){
- $depr = C('URL_PATHINFO_DEPR');
- $url = rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';
- }else{
- if($this->parameter && is_string($this->parameter)) {
- parse_str($this->parameter,$parameter);
- }elseif(is_array($this->parameter)){
- $parameter = $this->parameter;
- }elseif(empty($this->parameter)){
- unset($_GET[C('VAR_URL_PARAMS')]);
- $var = !empty($_POST)?$_POST:$_GET;
- if(empty($var)) {
- $parameter = array();
- }else{
- $parameter = $var;
- }
- }
- $parameter[$p] = '__PAGE__';
- $url = U('',$parameter);
- }
- //上下翻頁字符串
- $upRow = $this->nowPage-1;
- $downRow = $this->nowPage+1;
- if ($upRow>0){
- $upPage = "<li><a href='".str_replace('__PAGE__',$upRow,$url)."'>".$this->config['prev']."</a></li>";
- }else{
- $upPage = '';
- }
- if ($downRow <= $this->totalPages){
- $downPage = "<li><a href='".str_replace('__PAGE__',$downRow,$url)."'>".$this->config['next']."</a></li>";
- }else{
- $downPage = '';
- }
- // << < > >>
- if($nowCoolPage == 1){
- $theFirst = '';
- $prePage = '';
- }else{
- $preRow = $this->nowPage-$this->rollPage;
- $prePage = "<li><a href='".str_replace('__PAGE__',$preRow,$url)."' >上".$this->rollPage."頁</a></li>";
- $theFirst = "<li><a href='".str_replace('__PAGE__',1,$url)."' >".$this->config['first']."</a></li>";
- }
- if($nowCoolPage == $this->coolPages){
- $nextPage = '';
- $theEnd = '';
- }else{
- $nextRow = $this->nowPage+$this->rollPage;
- $theEndRow = $this->totalPages;
- $nextPage = "<li><a href='".str_replace('__PAGE__',$nextRow,$url)."' >下".$this->rollPage."頁</a></li>";
- $theEnd = "</li><a href='".str_replace('__PAGE__',$theEndRow,$url)."' >".$this->config['last']."</a></li>";
- }
- // 1 2 3 4 5
- $linkPage = "";
- for($i=1;$i<=$this->rollPage;$i++){
- $page = ($nowCoolPage-1)*$this->rollPage+$i;
- if($page!=$this->nowPage){
- if($page<=$this->totalPages){
- $linkPage .= "<li><a href='".str_replace('__PAGE__',$page,$url)."'>".$page."</a></li>";
- }else{
- break;
- }
- }else{
- if($this->totalPages != 1){
- $linkPage .= "<li><span class='current'>".$page."</span></li>";
- }
- }
- }
- $pageStr = str_replace(
- array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),
- array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);
- return $pageStr;
- }
- }
------------------------------------------------------------------------------
模板中使用:
<div class="pagination">{$page}</div> //基本樣式
<div class="pagination pagination-large">{$page}</div>//大號數(shù)字樣式
控制類代碼:
- $p = new Page ($count,10);
- $products = $this->product_model->where($where)->order($order.' '.$method)->limit($p->firstRow.','.$p->listRows)->select();
- $page = $p->show ();
- $this->assign( "page", $page );
【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。