abstract:<?phpnamespace app\index\controller; //命名空间use think\Controller; //系统控制器use app\index\model\Staff; //导入模型 设置模型别名 防止冲突class Staffs extends Controller{ public function demos() {
<?php
namespace app\index\controller; //命名空间
use think\Controller; //系统控制器
use app\index\model\Staff; //导入模型 设置模型别名 防止冲突
class Staffs extends Controller
{
public function demos()
{
//通过模型获取表中的数据
$statta = Staff::all(function($query){
$query->field(['id','name','sex','age','salary']);
//->where('salary','<','100');
});
//halt($statta); ===dump($statta);exit;
//模板赋值
$this->view->assign('statta',$statta);
//渲染模板
return $this->view->fetch();
}
public function demos1()
{
//分页配置
$config = [
'type' => 'bootstrap',
'var_page' =>'page'
];
//每页显示数量
$num = 5;
//是否是简单分页
$simple = false;
//用模型来获取所有的分页数据
$paginate = Staff::paginate($num,$simple,$config);
//渲染分页html代码 返回分页变量
$page = $paginate->render();
//将分页数据赋值给模板
$this->view->assign('statta',$paginate);
//将分页变量赋值给模板
$this->view->assign('page',$page);
//渲染模板
return $this->view->fetch();
}
}
<style type="text/css">
*{
margin: 0 auto;
text-decoration:none;
}
li{
list-style:none;
}
.row{
margin: 0 auto;
width: 800px;
height: auto;
background: #c7e5ff;
}
h3{
height:40px;
line-height:40px;
text-align: center;
background: #abcdef;
}
table{
border: 1px solid;
border-collapse: collapse;
width: 800px;
}
table th,td{
border: 1px solid;
text-align: center;
}
tr:nth-child(2n){
background: #abcdef;
}
.page{
text-align: center;
}
.page>ul{
margin-top: 10px;
overflow:hidden;
display:block;
}
.page>ul>li{
display: inline-block;
margin-right:6px;
}
.page>ul>li:last-child{
margin-right:0;
}
.page>ul>li>a,.page>ul>li>span{
border:1px solid #000;
display: inline-block;
padding: 5px 10px;
float: left;
}
</style>
<div class="container">
<div class="row">
<h3 class="">员工信息登记表</h3>
<table>
<tr>
<td>序列</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>工资</td>
</tr>
{volist name="statta" id="statts"}
<tr>
<td>{$statts.id}</td>
<td>{$statts.name}</td>
<td>{$statts.sex}</td>
<td>{$statts.age}</td>
<td>{$statts.salary}</td>
</tr>
{/volist}
</table>
<div class="page">{$page|raw}</div>
</div>
</div>
Correcting teacher:查无此人Correction time:2019-06-12 09:18:45
Teacher's summary:完成的不错。理解一些理论知识,会让你代码写的更好。继续加油