分享一个3.1.3多筛选分页路由,我是新手,如果不正确的地方望大家使劲喷
分享一个3.1.3多筛选分页路由,我是新手,如果不正确的地方望大家使劲喷
首先设置路由规则,因为我的是筛选是类所以路由设置为
'/^list\/(\d+)_(\d+)_(\d+)_(\d+)_(\d+)$/' => 'Index/List/index?r=:1&t=:2&n=:3&y=:4&p=:5',
然后方法中写
$this->p = isset($_GET['p'])?(int)$_GET['p'] : 1;
设置初始的页码,其他的按照正常的查询写就可以了
前台
<a href="{:U('/list/'.$v['id'].'_'.$t.'_'.$n.'_'.$y.'_'.$p)}">{$v.region}</a>
然后修改分页类,我是又另外复制了show方法
/**
* 分页显示输出
* @access public
*/
public function routeShow() {
if(0 == $this->totalRows) return '';
$p = $this->varPage;
$nowCoolPage = ceil($this->nowPage/$this->rollPage);
// 分析分页参数
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__';
$parameter=implode('_',$parameter);
$url = U('/list/'.$parameter);
}
//上下翻页字符串
$upRow = $this->nowPage-1;
$downRow = $this->nowPage+1;
if ($upRow>0){
$upPage = "<a href='".str_replace('__PAGE__',$upRow,$url)."'>".$this->config['prev']."</a>";
}else{
$upPage = '';
}
if ($downRow <= $this->totalPages){
$downPage = "<a href='".str_replace('__PAGE__',$downRow,$url)."'>".$this->config['next']."</a>";
}else{
$downPage = '';
}
// << < > >>
if($nowCoolPage == 1){
$theFirst = '';
$prePage = '';
}else{
$preRow = $this->nowPage-$this->rollPage;
$prePage = "<a href='".str_replace('__PAGE__',$preRow,$url)."' ><<</a>"; //上5页改成了 <<
$theFirst = "<a href='".str_replace('__PAGE__',1,$url)."' >".$this->config['first']."</a>";
}
if($nowCoolPage == $this->coolPages){
$nextPage = '';
$theEnd = '';
}else{
$nextRow = $this->nowPage+$this->rollPage;
$theEndRow = $this->totalPages;
$nextPage = "<a href='".str_replace('__PAGE__',$nextRow,$url)."' >>></a>"; // 下5页 改成了 >>
$theEnd = "<a href='".str_replace('__PAGE__',$theEndRow,$url)."' >".$this->config['last']."</a>";
}
// 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 .= "<a href='".str_replace('__PAGE__',$page,$url)."'>".$page."</a>"; //去掉了此处的空格
}else{
break;
}
}else{
if($this->totalPages != 1){
// 当前页
$linkPage .= " <span class='current'>".$page."</span>";
}
}
}
$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;
}
对链接重组
最后,如果没有筛选的链接路由
'/^list\/(\d+)$/' => 'Index/List/index?p=:1',
有不明白的在评论中留,尽力解答