批改状态:合格
老师批语:
控制器代码
<?php
namespace app\index\Controller;
use think\Controller;
use app\index\model\StaffList as StaffTest;
class Stafflist extends Controller
{
public function example()
{
$staff =StaffTest::all (function($query){
$query->field(['staff_id','name','sex','age','salary']);
});
// dump($staff);exit;
$this->view->assign('staff',$staff);
return $this->view->fetch();
}
public function example2()
{
$config=[
'type' =>'bootstrap',
'var_page'=>'page'
];
$num =5;
$simple =false;
$paginate= StaffTest::paginate($num,$simple,$config);
$page = $paginate->render();
$this->view->assign('staff',$paginate);
$this->view->assign('page',$page);
return $this->view->fetch('example');
}
}
?>点击 "运行实例" 按钮查看在线实例
用foreach分页显示
{load href="/static/bootstrap/css/bootstrap.css"}
<div class="container">
<div class="row">
<h2 class="text-center">员工信息表</h2>
<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>
{//assign name="staff" value=":\app\index\model\StaffList::all()" /}
{foreach $staff as $staffs}
<tr>
<td>{$staffs.staff_id}</td>
<td>{$staffs.name}</td>
<td>{$staffs.sex}</td>
<td>{$staffs.age}</td>
<td>{$staffs.salary}</td>
</tr>
{/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" /}点击 "运行实例" 按钮查看在线实例

用volist分页
{load href="/static/bootstrap/css/bootstrap.css"}
<div class="container">
<div class="row">
<h2 class="text-center">员工信息表</h2>
<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>
{volist name="staff" id="staffs"}
{//eq name="mod" value="0"}
<tr>
<td>{$staffs.staff_id}</td>
<td>{$staffs.name}</td>
<td>{//$staffs.sex}
{in name="staffs.sex" value="0,1" }
{if $staffs.sex==0}
男
{else }
女
{/if}
{/in}
</td>
<td>{$staffs.age}</td>
<td>{$staffs.salary}</td>
{///eq}
</tr>
{/volist}
</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" /}点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号