摘要: //template.php 配置常量 _CSS_ 'tpl_replace_string' =>[  
//template.php 配置常量 _CSS_
'tpl_replace_string' =>[
'_CSS_' =>str_replace('index.php', '', $_SERVER['SCRIPT_NAME']) ]
//index.php
<?php
namespace app\index\controller;
use think\Controller;
use app\model\User;
class Index extends Controller{
public function index() {
return $this->view->fetch();
}
public function paginator(){
//配置title變量
$this->view->assign('user','員工注冊(cè)信息表');
//配置分頁變量
$config=[ 'var_page' => 'page' ];
//每頁顯示記錄數(shù)
$num = 5;
//是否為簡(jiǎn)單分頁
$simple = false;
//通過模型__callstatic調(diào)用Query類函數(shù)paginate
$paginate = User::paginate($num,$simple,$config);
//渲染分頁
$page = $paginate->render();
//配置paginate變量
$this->view->assign('ress',$paginate);
//配置page變量
$this->view->assign('page',$page);
//渲染模板
return $this->view->fetch();
}
}
//paginator.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="_CSS_static/image/favicon.ico">
<link rel="stylesheet" type="text/css" href="_CSS_static/layui/css/layui.css">
<script type="text/javascript" src="_CSS_static/layui/layui.js"></script>
<style type="text/css">
//分頁居中樣式
.page{width:100%;padding-top:20px; text-align: center;} .pagination{display: inline-block;}
.pagination li{float:left;margin: 0 10px;line-height: 30px;}
//當(dāng)前頁面為紅色
.active{background: red;height:30px;width:30px;color:#ffffff;}
</style>
<title>{$user}</title>
</head>
<body>
<h2 style="text-align:center;margin-top:30px;">{$user}</h2>
<table class="layui-table" style="width:60%;margin: 10px auto;text-align: center!important;">
<colgroup>
<col width="60">
<col width="50">
<col width="120">
<col width="150">
</colgroup>
<thead>
<tr>
<th>序號(hào)</th>
<th>ID</th>
<th>用戶名</th>
<th>性別</th>
<th>郵箱</th>
<th>密碼</th>
<th>描述</th>
<th>工資</th>
</tr>
</thead>
<tbody>
{volist name="ress" id="res"}
<tr>
<td>{$i}</td>
<td>{$res.user_id}</td>
<td>{$res.username}</td>
<td>
{in name="res.sex" value="0,1"}
{if $res.sex == 0}
女
{else /}
男
{/if}
{/in}
</td>
<td>{$res.email}</td>
<td>{$res.password}</td>
<td>{$res.detail}</td>
<td>{$res.salary}</td>
</tr>
{/volist}
</tbody>
</table>
<div class="page">{$page|raw}</div>
</body>
</html>
批改老師:天蓬老師批改時(shí)間:2019-11-12 11:18:59
老師總結(jié):原生文件上傳非常麻煩的, 框架中做了大量封裝后, 簡(jiǎn)單多了