分页的用法
<?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'); } }
<!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>
效果图
成功可以复制!!!绝不可以粘贴!!!