博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ThinkPHP/---layui 分页
阅读量:6220 次
发布时间:2019-06-21

本文共 2520 字,大约阅读时间需要 8 分钟。

Model(base)

 

 

class Base extends Model {
protected $autoWriteTimestamp = true; public $page = ''; public $size = ''; public $from = ''; public function getTableList($data) {
$query = http_build_query($data); $where = []; if(!empty($data['start']) && !empty($data['end'])) {
$where['create_time'] = [['>=',strtotime($data['start'])],['<=',strtotime($data['end'])]]; } if(!empty($data['username'])){
$where['user_name'] = $data['username']; } $where['status'] = [ 'neq',Config('code.all_user_delete') ]; $this->getSizeAndPage($data); $result['tableList'] = $this->getTableListCondition($where); $result['tableListCount'] = $this->getTableListByConditionCount($where); $result['pagetotal'] = ceil($result['tableListCount']/$this->size); $result['page'] = $this->page; $result['query'] = $query; return $result; } public function getSizeAndPage($data) {
$this->page = !empty($data['page']) ? $data['page'] : 1; $this->size = !empty($data['size']) ? $data['size'] : 1; $this->from = ($this->page - 1) * $this->size; } public function getTableListCondition($data,$from=0,$size=5) {
if(empty($data['status'])){
$data['status']=[ 'neq',-1 ]; } $order=['id'=>'ASC']; $result = $this->where($data)->order($order)->limit($from,$size)->select(); return $result; } public function getTableListByConditionCount($where) {
if(empty($where['status'])){
$where['status']=[ 'neq',-1 ]; } $result = $this->where($where)->count(); return $result; } } Controller
public function index() {
$data = input('param.'); $result = model('User')->getTableList($data); $this->assign('curr',$result['page']); $this->assign('userlist',$result['tableList']); $this->assign('userlistcount',$result['tableListCount']); $this->assign('query',$result['query']); $this->assign('start',empty($data['start'])?'':$data['start']); $this->assign('end',empty($data['end'])?'':$data['end']); $this->assign('username',empty($data['username'])?'':$data['username']); $this->assign('pagetotal',$result['pagetotal']); return $this->fetch(); } view(js)
 
 
 

 

转载于:https://www.cnblogs.com/Gupq/p/10096696.html

你可能感兴趣的文章
操丛数据
查看>>
微软windows 8.1 Preview 预览版发布下载
查看>>
linux下的Sybase安装
查看>>
Windows下无法用django连接MySQL解决办法一例
查看>>
python 学习记录
查看>>
GCMail邮件系统怎样限制内外网邮件收发?
查看>>
Linux 定制版 作秀 And 创新 ?!
查看>>
如何使用投影仪
查看>>
论个人网站备份的重要性
查看>>
Android路由框架-ARouter详解
查看>>
Android编程规范与常用技巧
查看>>
mysql java.sql.SQLException: Unknown system variab
查看>>
input=file accept 类型
查看>>
在浏览器中进行深度学习:TensorFlow.js (十)构建一个推荐系统
查看>>
Getting iOS Done | 搞定iOS7 0 万事俱备
查看>>
DSL与函数式编程
查看>>
微信图片反防盗链的方法(此图片来自微信公众平台,未经允许不可引用)
查看>>
static_cast,const_cast,dynamic_cast,reinterpret...
查看>>
玩静态资源加密验证
查看>>
phpstorm 快捷键和搜狗输入法冲突
查看>>