3.1.3多筛选分页路由

原创
2016-06-07 11:37:49 966浏览
分享一个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; 设置初始的页码,其他的按照正常的查询写就可以了
前台{$v.region}然后修改分页类,我是又另外复制了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 = "".$this->config['prev']."";
}else{
$upPage = '';
}

if ($downRow <= $this->totalPages){
$downPage = "".$this->config['next']."";
}else{
$downPage = '';
}
// << < > >>
if($nowCoolPage == 1){
$theFirst = '';
$prePage = '';
}else{
$preRow = $this->nowPage-$this->rollPage;
$prePage = "<<"; //上5页改成了 <<
$theFirst = "".$this->config['first']."";
}
if($nowCoolPage == $this->coolPages){
$nextPage = '';
$theEnd = '';
}else{
$nextRow = $this->nowPage+$this->rollPage;
$theEndRow = $this->totalPages;
$nextPage = ">>"; // 下5页 改成了 >>
$theEnd = "".$this->config['last']."";
}
// 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 .= "".$page.""; //去掉了此处的空格
}else{
break;
}
}else{
if($this->totalPages != 1){
// 当前页
$linkPage .= " ".$page."";
}
}
}
$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',有不明白的在评论中留,尽力解答

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

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