abstract:<?phpnamespace app\index\controller; //命名空間use think\Controller; //系統(tǒng)控制器use app\index\model\Staff; //導入模型 設(shè)置模型別名 防止沖突class Staffs extends Controller{ public function demos() {
<?php
namespace app\index\controller; //命名空間
use think\Controller; //系統(tǒng)控制器
use app\index\model\Staff; //導入模型 設(shè)置模型別名 防止沖突
class Staffs extends Controller
{
public function demos()
{
//通過模型獲取表中的數(shù)據(jù)
$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'
];
//每頁顯示數(shù)量
$num = 5;
//是否是簡單分頁
$simple = false;
//用模型來獲取所有的分頁數(shù)據(jù)
$paginate = Staff::paginate($num,$simple,$config);
//渲染分頁html代碼 返回分頁變量
$page = $paginate->render();
//將分頁數(shù)據(jù)賦值給模板
$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:完成的不錯。理解一些理論知識,會讓你代碼寫的更好。繼續(xù)加油