1.控制器代码Users:
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Users as UsersModel;
use think\facade\Request;
class Users extends Controller{
public function pagelist(){
$config = ['type'=>'bootstrap','var_page'=>'page'];
$num = 5;
$simple = false;
$list = UsersModel::paginate($num, $simple, $config);
$page = $list->render();
$this->view->assign('list',$list);
$this->assign('page',$page);
return $this->fetch();
}
2.view视图代码Users/pagelist:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数据分页</title>
</head>
<body>
<div class="col-md-8">
<table class="table text-center table-hover">
<tr class="info">
<td>ID</td>
<td>用户名</td>
<td>性别</td>
</tr>
{foreach name="list" item="val"}
<tr>
<td>{$val.id}</td>
<td>{$val.name}</td>
<td>{//$val.sex}
{in name="$val.sex" value="0,1"}
{if $val.sex == 0}男
{else /}女
{/if}
{/in}
</td>
</tr>
{/foreach}
{//volist name="list" item="val"}
<tr>
<td>{$val.id}</td>
<td>{$val.name}</td>
<td>{//$val.sex}
{in name="$val.sex" value="0,1"}
{if $val.sex == 0}男
{else /}女
{/if}
{/in}
</td>
</tr>
{///volist}
</table>
{$page|raw}
</div>
</body>
</html>