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

本文共 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

你可能感兴趣的文章
v140平台工具集与v110工具集选择
查看>>
EF6+Sqlite连接字符串的动态设置
查看>>
下拉加载更多
查看>>
您是哪一种类型的老板?
查看>>
SQL SERVER 2012 只能识别20个CPU的问题
查看>>
设计模式(十)外观模式
查看>>
C/C++语言中Static的作用详述
查看>>
[Android Samples视频系列之ApiDemos] App-Activity-Recreate
查看>>
ASP开发基础
查看>>
MYSQL性能调优
查看>>
LVM自动扩容
查看>>
笔记整理4
查看>>
idea文件折叠显示出来配置
查看>>
SQLSERVER中的非工作时间不得插入数据的触发器的实现
查看>>
如何写出兼容大部分浏览器的CSS 代码
查看>>
第二阶段冲刺第八天,6月7日。
查看>>
java的左移位(<<)和右移位(>>)和无符号右移(>>>)
查看>>
struts2 action 返回类型分析
查看>>
【原创】FPGA开发手记(三) PS/2键盘
查看>>
linux统计多个文件大小总和
查看>>