相思资源网 Design By www.200059.com

本文实例讲述了PHP封装的完整分页类。分享给大家供大家参考,具体如下:

<"limit ".($this->page-1)*$this->pagesize.",".$this->pagesize;  //分页语句
    $this->url = $this->setUrl();  //地址
  }
  //分页语句
  public function limit(){
    return $this->limit;
  }
  //当前的url地址
  public function setUrl(){
    $server = $_SERVER['REQUEST_URI'];
    $im = explode('/',$server);
    if(empty($_SERVER['PATH_INFO'])){
      $array = array_splice($im,2,0,array('2'=>'index.php'));
    }
    $controller = $im[3];
    $action = $im[4];
    if(empty($_SERVER['PATH_INFO'])){
      $servers = "http://".$_SERVER['HTTP_HOST']."/".$im[1]."/".$controller."/".$action."/";
    }else{
      $servers = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."/".$controller."/".$action."/";
    }
    return $servers;
    //return $im;
  }
  //首页
  public function first(){
    //return $this->page;
    if($this->page > 1){
      return "<a href='".$this->url."page/1'>首页</a>";
    }
  }
  //上一页
  public function prev(){
    if($this->page==1){
      $page = 1;
    }else{
      $page = $this->page-1;
    }
    if($this->page > 1){
      return "<a href='".$this->url."page/".$page."'>上一页</a>";
    }else{
      return "<span class='disabled'>上一页</span>";
    }
  }
  //下一页
  public function next(){
    $page = $this->page+1;
    if($this->page < $this->pagenum){
      if(empty($this->page)){
        $pages = $this->page+2;
        return "<a href='".$this->url."page/".$pages."'>下一页</a>";
      }else{
        return "<a href='".$this->url."page/".$page."'>下一页</a>";
      }
    }else{
      return "<span class='disabled'>下一页</span>";
    }
  }
  //尾页
  public function last(){
    if($this->page < $this->pagenum){
      return "<a href='".$this->url."page/".$this->pagenum."'>尾页</a>";
    }
  }
  //分页
  public function showpage(){
    $page_ = "";
    $page_ .= $this->first();
    $page_ .= " ".$this->prev();
    $page_ .= " ".$this->next();
    $page_ .= " ".$this->last();
    return $page_;
  }
}

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

标签:
PHP,封装,分页类

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“PHP封装的完整分页类示例”

暂无PHP封装的完整分页类示例的评论...