问题描述:
tp5框架使用layui分页。
解决办法:
php
public function approle()
{
$limit=input('?get.limit')?input('get.limit'):20;
$page=input('?get.page')?input('get.page'):1;
$list=Db::name('app_role')->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
//分配变量
$this->assign(['list'=>$list['data'],'count'=>$list['total'],'limit'=>$limit,'page'=>$page]);
return view('approle');
}
html
<table class="layui-table">
<tr>
<th>编号</th>
<th>角色名称</th>
<th>角色描述</th>
<th>操作</th>
</tr>
{eq name="$count" value="0"}
<tr><td colspan="13" align="center">暂无数据</td></tr>
{else}
{volist name="list" id="list"}
<tr>
<td>{$list.id}</td>
<td>{$list.title}</td>
<td>{$list.info}</td>
<td>
<input type="button" class="layui-btn layui-btn-sm layui-btn-normal" value="编辑" onclick="location.href='{:url('approle_edit',['id'=>$list.id])}';">
<input type="button" class="layui-btn layui-btn-sm layui-btn-danger" value="删除" onclick="delinfo('{:url('approle_del',['id'=>$list.id])}','{:url('approle')}')">
<input type="button" class="layui-btn layui-btn-sm layui-btn-danger" value="查看权限" onclick="location.href='/admin/adminapp/rolemenu/roleid/{$list.id}'">
</td>
</tr>
{/volist}
{/eq}
</table>
<script>
layui.use(['laypage'], function(){
var laypage = layui.laypage;
laypage.render({
elem: 'page'
,limit: {$limit}
,count: {$count}
,curr: {$page}
,limits:[20,30,50,100]
,layout:['count','first','prev','page','next','last']
,jump: function(obj, first){
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
console.log(obj.limit); //得到每页显示的条数
if(!first){
location.href="?limit="+obj.limit+"&page="+obj.curr;
}
}
});
});
</script>