• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php自适应分页类

php 搞代码 3年前 (2022-01-23) 16次浏览 已收录 0个评论
<?php/**@Author: ray*@E-mail: [email protected]*@Date: 2016-3-29*@Explain: 自适应分页类**/class Page {    public $total;//总记录    public $pageSize;//每页大小    public $page;//当前页    public $pages;//总页数    public $link;//显示的页码数   1 2 3 4 5 6    public $left;//显示页码的左边数目    public $right;//显示页码的右边数目    public $pageId;//传值的变量名    public $prev;//上一页    public $next;//下一页    public $GP;//传值的方式  GET/POST    public $start;//中间显示页码的开始页码数    public $end;//中间显示页码的结束页码数        //渲染主题    public $theme=array('first','prev','link','next','last','total','info');        //构造方法    public function __construct($num, $pageSize, $link=7, $pageId='page', $GP='G'){        $this->total=$num;        $this->pageSize=$pageSize;        $this->link=$link;        $this->pageId=$pageId;        $this->GP=$GP;                $this->rule();    }            //计算页码    public function rule(){        //计算总页数        $this->pages=ceil($this->total/$this->pageSize);                //获得当前页        if($this->GP=='G'){//GET            $this->page=isset($_GET[$this->pageId])?$_GET[$this->pageId]:1;        }else{//POST            $this->page=isset($_POST[$this->pageId])?$_POST[$this->pageId]:1;        }        //约束当前页边界        $this->constraint();                //上下页        $this->prev=$this->page-1;        $this->next=$this->page+1;                //计算中间页码的开始和结束的页码数        //计算左右显示的页码数        if($this->link%2){//link为奇数            $this->left=$this->right=($this->link-1)/2;        }else{//link为偶数            $this->left=$this->link/2;            $this->right=$this->link-$this->left-1;        }        //初始化        $this->start=1;        $this->end=$this->pages;                if($this->pages>$this->link){            //1.起始页为1            if($this->pageleft){                $this->end=$this->link;            }            //2.中间            if(($this->page>$this->left) && (($this-><div style="color:transparent">本&文来源gaodai^.ma#com搞#代!码网</div><strong>搞gaodaima代码</strong>page+$this->right)pages)){                $this->start=$this->page-$this->left+1;                $this->end=$this->page+$this->right-1;            }            //3.结束页为pages            if(($this->page+$this->right)>=$this->pages){                $this->start=$this->pages-$this->link+1;            }        }            }            //边界约束    public function constraint(){        if($this->pagepage=1;        if($this->page>$this->pages) $this->page=$this->pages;    }        //获取当前页面的url    public function getUrl(){        return "http://".$_SERVER['HTTP_HOST'].($_SERVER['SERVER_PORT']!='80'?(':'.$_SERVER['SERVER_PORT']):'').$_SERVER['PHP_SELF'];    }        //获取limit    public function getLimit(){        return ($this->page-1)*$this->pageSize;    }        //改变主题    public function changeTheme(array $theme){        $this->theme=$theme;    }        //渲染页码     <span>    public function show(array $arr=array()){        if(!count($arr)){            $arr=$this->theme;        }        $url=$this->getUrl();        //首页、上一页约束        if($this->page==1){            $html['first']="<span>首页</span>";            $html['prev']="<span>上一页</span>";                    }else{            $html['first']="pageId."=1'>首页";            $html['prev']="pageId."=".$this->prev."'>上一页";                    }                $str='';        //起始点页码        if($this->start!=1){            $str='<span>...</span>';        }                for($i=$this->start;$iend;$i++){            if($i==$this->page){                $str.="<span>$i</span>";                continue;            }            $str.="pageId."=".$i."'>$i";        }        //结束点页码        if($this->end!=$this->pages){            $str.='<span>...</span>';        }                $html['link']=$str;                //下一页、末页约束        if($this->page==$this->pages){            $html['next']="<span>下一页</span>";            $html['last']="<span>末页</span>";                    }else{            $html['next']="pageId."=".$this->next."'>下一页";            $html['last']="pageId."=".$this->pages."'>末页";                    }        $html['total']="共有".$this->total."条结果 ";        $html['info']="当前为第".$this->page."/".$this->pages."页";                $res='';        foreach($arr as $v){            $res.=$html[$v];        }        return $res;    }}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php自适应分页类
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址