首页 >php教程 >php手册 >实现一个没有上下页链接的分页

实现一个没有上下页链接的分页

WBOY
WBOY原创
2016-06-07 11:36:181171浏览

实现一个没有上下页链接的分页
因为项目要求,只有"%linkPage%"部分,我的设置是: $Page->setConfig('theme',' %first%   %prePage%  %linkPage%  %nextPage% %end% ');效果是:实现一个没有上下页链接的分页
代码是抄来的,我拿来修改"show()"部分<?php <br />  // +----------------------------------------------------------------------<br>  // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]<br>  // +----------------------------------------------------------------------<br>  // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.<br>  // +----------------------------------------------------------------------<br>  // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )<br>  // +----------------------------------------------------------------------<br>  // | Author: liu21st <liu21st><br>  // |         lanfengye <zibin_5257><br> //  |         wakasann <xiaofosong><br>  // +----------------------------------------------------------------------<br>  class BootstrapPage {<br>     <br>     // 分页栏每页显示的页数<br>     public $rollPage = 5;<br>     // 页数跳转时要带的参数<br>     public $parameter  ;<br>     // 分页URL地址<br>     public $url     =   '';<br>     // 默认列表每页显示行数<br>     public $listRows = 20;<br>     // 起始行数<br>     public $firstRow    ;<br>     // 分页总页面数<br>     protected $totalPages  ;<br>     // 总行数<br>     protected $totalRows  ;<br>     // 当前页数<br>     protected $nowPage    ;<br>     // 分页的栏的总页数<br>     protected $coolPages   ;<br>     // 分页显示定制<br>     protected $config  =    array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'<span>最后一页</span>','theme'=>'<li><span> %totalRow% %header% %nowPage%/%totalPage% 页</span></li> %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% <li>%end%</li>');<br>     // 默认分页变量名<br>     protected $varPage;<br>     /**<br>      * 架构函数<br>      * @access public<br>      * @param array $totalRows  总的记录数<br>      * @param array $listRows  每页显示记录数<br>      * @param array $parameter  分页跳转的参数<br>      */<br>     public function __construct($totalRows,$listRows='',$parameter='',$url='') {<br>         $this->totalRows    =   $totalRows;<br>         $this->parameter    =   $parameter;<br>         $this->varPage      =   C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ;<br>         if(!empty($listRows)) {<br>             $this->listRows =   intval($listRows);<br>         }<br>         $this->totalPages   =   ceil($this->totalRows/$this->listRows);     //总页数<br>         $this->coolPages    =   ceil($this->totalPages/$this->rollPage);<br> <br>         $this->nowPage      =   !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1;<br>         if($this->nowPage             $this->nowPage  =   1;<br>         }elseif(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {<br>             $this->nowPage  =   $this->totalPages;<br>         }<br>         $this->firstRow     =   $this->listRows*($this->nowPage-1);<br>         if(!empty($url))    $this->url  =   $url; <br>     }<br>     public function setConfig($name,$value) {<br>         if(isset($this->config[$name])) {<br>             $this->config[$name]    =   $value;<br>         }<br>     }<br>     /**<br>      * 分页显示输出<br>      * @access public<br>      */<br>     public function show() {<br> <br>         if(0 == $this->totalRows) return '';<br>         $p              =   $this->varPage;<br>         $nowCoolPage    =   ceil($this->nowPage/$this->rollPage);<br>         // 分析分页参数<br>         if($this->url){<br>             $depr       =   C('URL_PATHINFO_DEPR');<br>             $url        =   rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';<br>         }else{<br>             if($this->parameter && is_string($this->parameter)) {<br>                 parse_str($this->parameter,$parameter);<br>             }elseif(is_array($this->parameter)){<br>                 $parameter      =   $this->parameter;<br>             }elseif(empty($this->parameter)){<br>                 unset($_GET[C('VAR_URL_PARAMS')]);<br>                 $var =  !empty($_POST)?$_POST:$_GET;<br>                 if(empty($var)) {<br>                     $parameter  =   array();<br>                 }else{<br>                     $parameter  =   $var;<br>                 }<br>             }<br>             $parameter[$p]  =   '__PAGE__';<br>             $url            =   U('',$parameter);<br>         }<br> <br>         //上下翻页字符串<br>         $upRow          =   $this->nowPage-1;<br>         $downRow        =   $this->nowPage+1;<br>         if ($upRow>0){<br>             $upPage     =    "<li><a>".$this->config['prev']."</a></li>";<br>         }else{<br>             $upPage     =    '';<br>         }<br> <br>         if ($downRow totalPages){<br>             $downPage   =   "<li><a>".$this->config['next']."</a></li>";<br>         }else{<br>             $downPage   =   '';<br>         }<br> <br>         //  >><br>         if($nowCoolPage == 1){<br>             $theFirst   =   '';<br>             $prePage    =   '';<br>         }else{<br>             $preRow     =   $this->nowPage-$this->rollPage;<br>             // $prePage    =   "<li><a>".L('page_prev')." ".$this->rollPage." ".L('page_pager')."</a></li>";<br>             $prePage    =   "<li><span> ... </span></li>";<br>             // $theFirst   =   "<li><a>".$this->config['first']."</a></li>";<br>             $theFirst   =   "<li><a>1</a></li>";<br>         }<br> <br> <br>         if($nowCoolPage == $this->coolPages){<br>             $nextPage   =   '';<br>             $theEnd     =   '';<br>         }else{<br>             $nextRow    =   $this->nowPage+$this->rollPage;<br>             $theEndRow  =   $this->totalPages;<br>             // $nextPage   =   "<li><a>".L('page_next')." ".$this->rollPage." ".L('page_pager')."</a></li>";<br>             $nextPage   =   "<li><span> ... </span></li>";<br>             // $theEnd     =   "<li><a>".$this->config['last']."</a></li>";<br>             $theEnd =  "<li><a>".$this->totalPages."</a></li>";<br>         }<br> <br> <br>         //数字链接<br>         // 1 2 3 4 5<br>         $linkPage = ""; //数字链接<br> <br>         for($i=1;$irollPage;$i++){<br>             $page       =   ($nowCoolPage-1)*$this->rollPage+$i;<br>             if($page!=$this->nowPage){<br>                 if($pagetotalPages){<br>                     $linkPage .= "<li><a>".$page."</a></li>";<br>                 }else{<br>                     break;<br>                 }<br>             }else{<br>                 if($this->totalPages != 1){<br>                     $linkPage .= "<li><a>".$page."</a></li>";<br>                 }<br>             }<br>         }<br> <br>         //修改最后一个为跳到下个分页组的<br>         if ($upRow>0){<br>             $page2       =  ($nowCoolPage-1)*$this->rollPage+($this->rollPage+1);<br>             if($page2 != $this->nowPage && $page2 totalPages){<br>                 $linkPage .= "<li><a>".$page2."</a></li>";<br>             }<br>         }<br>         //修改最后一个为跳到上个分页组的<br>         if ($downRow totalPages){<br>             $page2       =  ($nowCoolPage-1)*$this->rollPage;<br>             if($page2 != $this->nowPage && $page2 > 0 && $page2 totalPages){<br>                 $linkPage2 = "<li><a>".$page2."</a></li>";<br>                 $linkPage = $linkPage2.$linkPage;<br>             }<br>         }<br> <br>         $pageStr     =   str_replace(<br>             array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),<br>             array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);<br>         return $pageStr;<br>     }<br>  }</xiaofosong></zibin_5257></liu21st>

AD:真正免费,域名+虚机+企业邮箱=0元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn