侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

thinkPHP分页功能实例详解

ThinkPHP  /  管理员 发布于 8年前   225

本文实例讲述了thinkPHP分页功能。分享给大家供大家参考,具体如下:

interface ServiceInterFace:

StaticService 静态服务类:

abstract AbProduct  抽象商品管理类:

errorNum;    switch($errorNum){        case 0:            $data['status'] = 0;            $data['message'] = '收藏成功';            break;        case 1:            $data['status'] = 1;            $data['message'] = '收藏失败';            break;        case 2:            $data['status'] = 2;            $data['message'] = '已收藏';            break;        case 3:            $data['status'] = 3;            $data['message'] = '未登陆';            break;        case 4:            $data['status'] = 4;            $data['message'] = '缺少参数';            break;        default:            $data['status'] = 200;            $data['message'] = '未知错误';    }    return $data;  }

MemberModel 会员模型:

userId = getUserInfo(0);  }   /**   * 实例化本类   * @return MemberModel   */  public static function getInstance() {    return StaticService::getInstance(__CLASS__);  }   /**   *  获取登录用户信息   * @param string  $data 查询条件   * @return array   */  public function getUser($data = '') {    if(empty($data)){      return $this->where("id=".$this->userId)->find();    }else{      return $this->field($data)->where("id=".$this->userId)->find();    }  }  /**   * 修改用户信息   * @param array $data   * @param array $where 查询条件   */  public function editUserInfo($data, $where = '') {    if( $this->_before_check($data) === false ){      return $this->error['msg'];    }    if(!empty($where) && is_array($where)){      $condition[ $where[0] ] = array('eq', $where[1]);      return $this->where($condition)->save($data);    }    return $this->where("id=".$this->userId)->save($data);  }  /**   * 获取用户信息   * @param string $data 用户名   * return array()   */  public function checkUserInfo($str, $field = ''){    //注册类型    $info = CheckType($str);    $condition[$info] = array('eq',$str);    if(!empty($field)){      return $this->field($field)->where($condition)->find();    }    return $this->where($condition)->find();  }  /**   * 获取用户信息   * @param array $data 用户名   * return array()   */  public function getAccount($data){    //注册类型    $info = CheckType($data);    $condition['id'] = array('eq',$this->userId);    $condition[$info] = array('eq',$data);    return $this->where($condition)->find();  }  /**   * 修改用户密码   * @param array $data['id']用户ID   * @param $data['passWord']用户密码   * return true or false   */  public function upUserPassById($data){    $condition['id'] = array('eq',$data['id']);    $status = $this->where($condition)->save(array("password"=>md5($data['password'])));    if($status){        return TRUE;    }else {        return FALSE;    }  }  /**   * 校验用户的账号或者密码是否正确   * @param $data['username'] 用户名   * @param $data['password'] 密码   * return true or false   */  public function checkUserPasswd($data= array()){      $type = CheckType($data['username']);      $condition[$type] = array('eq',$data['username']);      $condition['password'] = array('eq',md5($data['password']));       return $this->where($condition)->find();  }  /**   * 网页登录校验token   * @param token string   * return bool   */  public function checkToken($token){      return $this->autoCheckToken($token);  }  /**   * 后台封号/解封   * param int $user_id   */  public function changeStatus($data){    if($this->save($data)){      return true;    }else{      return false;    }  }  protected function _before_check(&$data){    if(isset($data['username']) && empty($data['username'])){      $this->error['msg'] = '请输入用户名';      return false;    }    if(isset($data['nickname']) && empty($data['nickname'])){      $this->error['msg'] = '请输入昵称';      return false;    }    if(isset($data['realname']) && empty($data['realname'])){      $this->error['msg'] = '请输入真名';      return false;    }    if(isset($data['email']) && empty($data['email'])){      $this->error['msg'] = '请输入邮箱';      return false;    }    if(isset($data['mobile']) && empty($data['mobile'])){      $this->error['msg'] = '请输入手机号码';      return false;    }    if(isset($data['password']) && empty($data['password'])){      $this->error['msg'] = '请输入密码';      return false;    }    if(isset($data['headimg']) && empty($data['headimg'])){      $this->error['msg'] = '请上传头像';      return false;    }    return true;  }}

ProductModel 商品模型:

where($condition)->find();  }  /**   * 商品列表   * @param string $limit 查询条数   * @param array $data 查询条件   * @return array 二维数组   */  public function getProList($data = ''){    $condition['onsale'] = array('eq', $data['onsale']); //是否上架    $condition['status'] = array('eq', $data['status']); //状态    $condition['type'] = array('eq', $data['type']);  //分类    if(isset($data['limit']) && isset($data['order']) ){      $return =$this->where($condition)->limit($data['limit'])->order($data['order'])->select();    }else{      $return =$this->where($condition)->select();    }    return $return;  }  /**   * 添加商品   * @param array $data   * @return int   */  public function addProduct($data){    return $this->add($data);  }  /**   * 删除商品   *   */  public function delProduct($id){    $condition['id'] = array('eq', $id);    return $this->where($condition)->delete();  }  /**   * 修改商品   * @param string|int $id   * @param array $data   * @return   */  public function editProdcut($id, $data){    $condition['id'] = array('eq', $id);    return $this->where($condition)->save($data);  }  public function getProductInfo($product){    if(empty($product) || !isset($product['product_id'])){      return array();    }    $info = $this->getProOne($product['product_id']);    $product['name'] = $info['name'];    $product['store_id'] = $info['store_id'];    $product['price'] = $info['price'];    $product['m_price'] = $info['m_price'];    return $product;  }}

ProductManage 商品管理类:

getCollectList($page,$limit);    $showpage = create_pager_html($list['total'],$page,$limit);    $this->assign(get_defined_vars());    $this->display();  }  public function cancelCollect(){    $ids = field('ids');    $return = ProductManage::getInstance()->cancelProductCollect($ids);    exit(json_encode($return));  }}

functions.php 分页函数:

 $v) {      if ($k != 'page') {        $url[] = urlencode($k) . '=' . urlencode($v);      }    }    $url[] = 'page={page}';    $url = '?' . implode('&', $url);  }  if ($total <= $perpage)    return '';  $total = ceil($total / $perpage);  $pagecount = $total;  $total = ($maxpage && $total > $maxpage) ? $maxpage : $total;  $page = intval($page);  if ($page < 1 || $page > $total)    $page = 1;    $pages = '
上一页'; if ($page > 4 && $page <= $total - 4) { $mini = $page - 3; $maxi = $page + 2; } elseif ($page <= 4) { $mini = 2; $maxi = $total - 2 < 7 ? $total - 2 : 7; } elseif ($page > $total - 4) { $mini = $total - 7 < 3 ? 2 : $total - 7; $maxi = $total - 2; } for ($i = 1; $i <= $total; $i++) { if ($i != $page) { $pages .= '' . $i . ''; } else { $pages .= '' . $i . ''; } if ($maxi && $i >= $maxi) { $i = $total - 2; $maxi = 0; } if (($i == 2 or $total - 2 == $i) && $total > 10) { $pages .= ''; } if ($mini && $i >= 2) { $i = $mini; $mini = 0; } } $pages .= '= $total ? $total : $page + 1, $url) . '" rel="external nofollow" title="下一页" class="page_next">下一页共' . $totalcount . '条 / ' . $total . '页 '; return $pages;}

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • thinkPHP多表查询及分页功能实现方法示例
  • ThinkPHP实现分页功能
  • thinkphp实现分页显示功能
  • thinkphp分页实现效果
  • Thinkphp3.2.3分页使用实例解析
  • thinkphp3.2.3 分页代码分享
  • ThinkPHP3.2.3实现分页的方法详解
  • thinkPHP中分页用法实例分析
  • thinkphp分页集成实例


  • 上一条:
    完美解决在ThinkPHP控制器中命名空间的问题
    下一条:
    ThinkPHP 3.2.2实现事务操作的方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • thinkphp + mongodb项目中数据加载慢问题分析及解决(0个评论)
    • thinkphp6框架中封装redis操作类(0个评论)
    • thinkphp6框架中实现定时任务功能流程步骤(0个评论)
    • Thinkphp5.1框架中实现Session+Redis会话共享流程步骤(0个评论)
    • TP5框架版本5.0.10安全漏洞根据官方补丁修复,也是本站安全漏洞修复(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-12
    • 2018-01
    • 2018-02
    • 2020-03
    • 2021-07
    • 2021-12
    • 2022-05
    • 2022-06
    • 2022-09
    • 2023-01
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客