摘要:PHP代码块:<?php namespace app\index\controller; use think\Controller; use app\index\model\User; class Index extends Controller { public fun
PHP代码块:
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User;
class Index extends Controller
{
public function index()
{
$list = User::paginate(3);
$page = $list->render();
$this->view->list = $list;
$this->view->page = $page;
return $this->fetch();
}
}前端页面:
{load href="/static/bootstrap/css/bootstrap.css"}
<style>
.content{width: 600px;margin: 30px auto;text-align: center;}
</style>
<div class="content">
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
</tr>
{foreach $list as $k=>$v}
<tr>
<td>{$v.user_id}</td>
<td>{$v.user_name}</td>
<td>{$v.sex}</td>
<td>{$v.age}</td>
</tr>
{/foreach}
</table>
{$page|raw}
</div>
{load href="/static/js/jq_3.3.1_mi.js"}
{load href="/static/bootstrap/js/bootstrap.js"}显示效果:

总结:
用thinkphp5.1实现分页代码非常简单。
批改老师:天蓬老师批改时间:2019-03-19 09:24:21
老师总结:tp51将分页进行了封装,不过默认是bootstrap,这点不太灵活, 不过更改也是可以的