Tp3.2自带分页功能

Tp3.2自带分页功能,优化多数据渲染

后端:

public function index(){
        $User = M('user'); // 实例化User对象
        $count      = $User->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $userres = $User->limit($Page->firstRow.','.$Page->listRows)->order("id desc")->select();
        $this->assign('userres',$userres);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display(); // 输出模板
    }

 前端:

<table id="exampleTableEvents" data-height="500" data-mobile-responsive="true" >
	<thead>
	<tr>
		<th>操作</th>
		<th data-field="title">评论</th>
	</tr>
	</thead>
    <volist name="cmtlistres" id="res">
	    <tr>
		<td>
		<a href="#" class="glyphicon glyphicon-trash" onclick="myDelate(this)" data-id="{$res.id}">删除</a>
		</td>
		<td>{$res.content}</td>
	    </tr>
	</volist>
</table>
<div class="my_pages">{$page}</div>

css:

.my_pages{float: right}
.my_pages a,.my_pages span {
    display:inline-block;
    padding:2px 10px;
    border:1px solid #f0f0f0;
    -webkit-border-radius:3px;
    -moz-border-radius:3px;
    border-radius:3px;
    font-size: 14px;
}
.my_pages a,.my_pages li {
    display:inline-block;
    list-style: none;
    text-decoration:none; color:#58A0D3;
}
.my_pages a.first,.my_pages a.prev,.my_pages a.next,.my_pages a.end{
    margin:0 auto;
}
.my_pages a:hover{
    border-color:#50A8E6;
}
.my_pages span.current{
    background:#50A8E6;
    color:#FFF;
    font-weight:700;
    border-color:#50A8E6;
}

效果:

猜你喜欢

转载自blog.csdn.net/qq_21041889/article/details/108143139
今日推荐