ThinkPHP/---layui 分页

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)
<script type="text/javascript" src="__STATIC__/js/laypage/1.2/laypage.js"></script>
<script>
var url = '{:url("User/index")}'+'?{$query}';
//alert(url);
laypage({
cont: 'laypage', //容器。值支持id名、原生dom对象,jquery对象,
pages: '{$pagetotal}', //总页数
skin: '#5FB878', //皮肤
curr :'{$curr}',
jump: function(e, first){ //触发分页后的回调
if(!first){ //一定要加此判断,否则初始时会无限刷新
//alert(url+'?page='+e.curr);
location.href = url+'&page='+e.curr;
}
}
});

</script>


 

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值