当前位置: 首页 > 后端技术 > PHP

php分页类

时间:2023-03-29 22:45:30 PHP

初始化(1000,20);*$page->setNotActiveTemplate('{a}');*$page->setActiveTemplate('{a}');*echo$page->show();***@authorwherethewindlives*/classPage{/***条目总数*/private$total;/***每页的大小*/private$pageSize;/***总页码*/private$pageNum;/***当前页面*/private$page;/***地址*/private$uri;/***分页变量*/private$pageParam;/***限制XX,XX*/private$limit;/***数字分页显示*/private$listnum=8;/***分页显示模板*可用变量参数*{total}数据项总数*{pagesize}每页显示项数*{start}本页起始数*{end}本页结束数*{pagenum}一共多少页*{frist}第一页*{pre}上一页*{next}下一页*{last}最后一页*{list}号分页*{goto}跳转按钮*/private$template='

有{total}条数据显示{pagesizeon每页}条数据,本页{start}-{end}条数据共{pagenum}页
    {frist{pre}{list}{next}{last}{goto}
';/***当前选择的页面链接模板*/private$activeTemplate='{text}';/***未选中的分页链接模板*/private$notActiveTemplate='
  • {text}
  • ';/***显示文本设置*/private$config=array('frist'=>'firstpage','pre'=>'previouspage','next'=>'Nextpage','last'=>'最后一页');/***初始化*@paramtype$total文章总数*@paramtype$pageSize每页大小*@paramtype$paramurl附加参数*@paramtype$pageParam分页变量*/publicfunctioninit($total,$页面大小,$param='',$pageParam='page'){$this->total=intval($total);$this->pageSize=intval($pageSize);$this->pageParam=$pageParam;$this->uri=$this->geturi($param);$this->pageNum=ceil($this->total/$this->pageSize);$this->page=$this->setPage();$this->limit=$this->setlimit();}/***设置分页模板*@paramtype$template模板配置*/publicfunctionsetTemplate($template){$this->template=$template;}/***设置选择的分页模板*@paramtype$activeTemplate模板配置*/publicfunctionsetActiveTemplate($activeTemplate){$this->activeTemplate=$activeTemplate;}/***设置未选中的分页模板*@paramtype$notActiveTemplate模板配置*/publicfunctionsetNotActiveTemplate($notActiveTemplate){$this->notActiveTemplate=$notActiveTemplate;}/***返回分页*@returnt类型*/publicfunctionshow(){returnstr_ireplace(array('{total}','{pagesize}','{start}','{end}','{pagenum}','{frist}','{pre}','{next}','{last}','{list}','{goto}',),array($this->total,$this->setPageSize(),$this->star(),$this->end(),$this->pageNum,$this->frist(),$this->prev(),$this->next(),$this->last(),$this->pagelist(),$this->gopage(),),$this->template);}/***获取limit起始数*@returntype*/publicfunctiongetOffset(){return($this->page-1)*$this->pageSize;}/***设置LIMIT*@returntype*/privatefunctionsetlimit(){return"limit".($t他的->页面-1)*$this->pageSize。",{$this->pageSize}";}/***获取limit*@paramtype$args*@returntype*/publicfunction__get($args){if($args=="limit"){return$this->limit;}else{返回空值;}}/***初始化当前页*@returnint*/privatefunctionsetPage(){if(!empty($_GET[$this->pageParam])){if($_GET[$this->pageParam]>0){如果($_GET[$this->pageParam]>$this->pageNum)返回$this->pageNum;否则返回$_GET[$this->pageParam];}}返回1;}/***初始化url*@paramtype$param*@returnstring*/privatefunctiongeturi($param){$url=$_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],"?")?"":"?")。$参数;$parse=parse_url($url);如果(isset($parse["query"])){parse_str($parse["query"],$params);取消设置($params[“页面”]);$url=$parse["路径"].“?”.http_build_query($params);返回$网址;}else{返回$url;}}/***本页开始条数*@returnint*/privatefunctionstar(){if($this->total==0){return0;}else{return($this->page-1)*$this->pageSize+1;}}/***本页结束条数*@returntype*/privatefunctionend(){returnmin($this->page*$this->pageSize,$this->total);}/***设置当前页大小*@returntype*/privatefunctionsetPageSize(){return$this->end()-$this->star()+1;}/***首页*@returntype*/privatefunctionfrist(){$html='';如果($this->page==1){$html.=$this->replace("{$this->uri}&page=1",$this->config['frist'],true);}else{$html.=$this->replace("{$this->uri}&page=1",$this->config['frist'],false);}return$html;}/***上一页*@returntype*/privatefunctionprev(){$html='';if($this->page>1){$html.=$this->replace($this->uri.'&page='.($this->page-1),$this->config['pre'],false);}else{$html.=$this->replace($this->uri.'&page='.($this->page-1),$this->config['pre'],true);}返回$html;}/***分页数字列表*@returntype*/privatefunctionpagelist(){$linkpage="";$lastlist=floor($this->listnum/2);for($i=$lastlist;$i>=1;$i--){$page=$this->page-$i;if($page>=1){$linkpage.=$this->replace("{$this->uri}&page={$page}",$page,false);}else{continue;}}$linkpage.=$this->replace("{$this->uri}&page={$this->page}",$this->page,true);for($i=1;$i<=$lastlist;$i++){$page=$this->page+$i;if($page<=$this-;>pageNum){$linkpage.=$this->replace("{$this->uri}&page={$page}",$page,false);}else{break;}}return$linkpage;}/***Private*@returntype*/privatefunctionnext(){$html='';if($this->page<$this->pageNum){$html.=$this->replace($this).->uri.'&page='.($this->page+1),$this->config['next'],false);}else{$html.=$this->replace($this->}返回$h.($this->page+1)}返回$hTM;}/***最后一页*@returntype*/privatefunctionlast(){$html='';if($this->page==$this->pageNum){$html.=$this->replace($this->uri.'&page='.($this->pageNum),$this->config['最后'],真);}else{$html.=$this->replace($this->uri.'&page='.($this->pageNum),$this->config['last'],false);}返回$html;}/***跳转按钮*@returnstring*/privatefunctiongopage(){$html='';$html.='page.'"onkeydown="javascript:if(event.keyCode==13){varpage=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}"style="width:25px;"/>'.$this->pageNum.')?'.$this->页面数。':this.previousSibling.value;location=\''。$this->uri。'&page=\'+page+\'\'"value="GO"/>';return$html;}/***模板替换*@paramtype$replace替换内容*@paramtype$result条件*@return输入*/privatefunctionreplace($url,$text,$result=true){$template=($result?$this->activeTemplate:$this->notActiveTemplate);$html=str_replace('{url}',$url,$template);$html=str_replace('{text}',$text,$html);返回$html;}