model\Staff.php
实例
<?php namespace app\index\model; use think\Model; class Staff extends Model { protected $table = 'staff'; protected $pk = 'staff_id'; }
运行实例 »
点击 "运行实例" 按钮查看在线实例
view\staff\demo2.html
实例
{load href="/static/bootstrap/css/bootstrap.css"} <div class="container"> <div class="row"> <h3 class="text-center">员工信息登记表</h3> <div class="col-md-8 col-md-offset-2"> <table class="table table-bordered table-hover text-center"> <tr class="info"> <td>ID</td> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>工资</td> </tr> {foreach $staffs as $staff} {//volist name="staffs" id="staff"} <tr> <td>{$staff.staff_id}</td> <td>{$staff.name}</td> <td> {//$staff.sex} {//性别必须是0或1,才是合法数据} {in name="staff.sex" value="0,1"} {if $staff.sex == 0} 男 {else /} 女 {/if} {/in} </td> <td> {//$staff.age} {//between标签} {between name="staff.age" value="20,30"} 很年轻嘛 {else /} 快退休了 {/between} </td> <td>{$staff.salary}</td> </tr> {///volist} {/foreach} </table> <div class="text-center"> {$page|raw} </div> </div> </div> </div> {load href="/static/jquery/jquery-3.3.1.js"} {load href="/static/bootstrap/js/bootstrap.js"}
运行实例 »
点击 "运行实例" 按钮查看在线实例
controller\Staff.php
实例
<?php namespace app\index\controller; use think\Controller; use app\index\model\Staff as StaffModel; use think\facade\Request; class Staff extends Controller { //分页查询 public function demo2() { //分页配置 $config = [ 'type' => 'bootstrap', 'var_page' => 'page' ]; //每页显示的数量 $num = 5; //是否是简单分页?就是只有:上一页、下一页 $simple = false; //用模型来获取所有的分页数据:think\Paginate $paginate = StaffModel::paginate($num, $simple, $config); //渲染分页HTML代码,返回分页变量 $page = $paginate->render(); //将分页数据赋值给模板 $this->view->assign('staffs', $paginate); //将分页变量赋值给模板 $this->view->assign('page', $page); //渲染模板 return $this->view->fetch(); } }
运行实例 »
点击 "运行实例" 按钮查看在线实例