Correction status:Uncorrected
Teacher's comments:
<?php namespace app\index\controller; use think\Controller; // use think\Request; use app\index\model\Staff as StaffModel; use think\facade\Request; class Staff extends Controller { // foreach 分页查询 public function foreach() { $config = [ 'type' => 'bootstrap', 'var_page' => 'page', ]; $num = 5; $simple = false; $paginate = StaffModel::paginate($num, $simple, $config); $page = $paginate->render(); // $result = StaffModel::all(function($query) { // $query->field(['staff_id', 'name', 'sex', 'age', 'salary']); // }); // halt($result); $this->view->assign('staffs', $paginate); $this->view->assign('page', $page); return $this->fetch(); } // volist 分页 public function volist() { $config = [ 'type' => 'bootstrap', 'var_page' => 'page', ]; $num = 5; $simple = false; $paginate = StaffModel::paginate($num, $simple, $config); $page = $paginate->render(); // $result = StaffModel::all(function($query) { // $query->field(['staff_id', 'name', 'sex', 'age', 'salary']); // }); // halt($result); $this->view->assign('staffs', $paginate); $this->view->assign('page', $page); return $this->fetch(); } }
点击 "运行实例" 按钮查看在线实例
{load href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.css" /} <div class="container"> <div class="row"> <div class="col-md-6 com-md-offset-3"> <h3 class="text-center">表格标签</h3> <table class="table table-bordered table-hover text-center"> <tr class="info"> <td>ID</td> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>工资</td> </tr> {empty name="staffs"} <h3 class="danger" >数据为空</h3> {else /} {foreach $staffs as $staff} <tr> <td>{$staff.staff_id}</td> <td>{$staff.name}</td> <td>{$staff.age}</td> <td> {in name="staff.sex" value="0,1"} {if ($staff.sex == 0)} 男 {else /} 女 {/if} {/in} </td> <td>{$staff.salary}</td> </tr> {/foreach} {/empty} </table> <div class="d-flex justify-content-center" aria-label="Page navigation example">{$page|raw}</div> </div> </div> </div> {load href="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" /} {load href="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js" /}
点击 "运行实例" 按钮查看在线实例
{load href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.css" /} <div class="container"> <div class="row"> <div class="col-md-6 com-md-offset-3"> <h3 class="text-center">表格标签</h3> <table class="table table-bordered table-hover text-center"> <tr class="info"> <td>ID</td> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>工资</td> </tr> {empty name="staffs"} <h3 class="danger" >数据为空</h3> {else /} {volist name="staffs" id="staff"} <tr> <td>{$staff.staff_id}</td> <td>{$staff.name}</td> <td> {between name="staff.age" value="20,30"} 90后 {/between} {between name="staff.age" value="31,50"} 中腻男 {/between} {between name="staff.age" value="51,9999"} 空巢老人 {/between} </td> <td> {in name="staff.sex" value="0,1"} {if ($staff.sex == 0)} 男 {else /} 女 {/if} {/in} </td> <td>{$staff.salary}</td> </tr> {/volist} {/empty} </table> <div class="d-flex justify-content-center" aria-label="Page navigation example">{$page|raw}</div> </div> </div> </div> {load href="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" /} {load href="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js" /}
点击 "运行实例" 按钮查看在线实例