分页的用法

<?php
/**
 * Created by PhpStorm.
 * User: admin.Li
 * Date: 2018/5/16
 * Time: 11:53
 */

namespace app\index\controller;


use think\Controller;
use think\Db;

class User extends Controller
{
    public function index(){
        //查询数据
        $data=Db::table('user')->paginate(3);
        //$data=Db::table('user')->paginate(3,true);
        //dump($data);

        //分配数据
        $this->assign('users',$data);

        //加载页面
        return $this->fetch('index');
    }
}
User.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分页显示数据</title>
</head>
<body>
<table border="1" width="800px" align="center">
    <tr>
        <th>ID</th>
        <th>NAME</th>
        <th>PASS</th>
    </tr>
    {volist name='users' id='value'}
    <tr>
        <td>{$value.id}</td>
        <td>{$value.name}</td>
        <td>{$value.pass}</td>
    </tr>
    {/volist}
</table>
{$users->render()}
</body>
</html>
user_index.html

效果图

 

posted @ 2018-05-16 15:07  奔跑的茄子  阅读(219)  评论(0编辑  收藏  举报