摘要:本章主要學(xué)習(xí)了循環(huán)標(biāo)簽及列表的分頁顯示,通過學(xué)習(xí),實(shí)現(xiàn)了用戶列表的分頁顯示,代碼如下:app/index/controller/User.php<?php namespace app\index\controller; use app\model\User as UserModel; use think\Controller; use&n
本章主要學(xué)習(xí)了循環(huán)標(biāo)簽及列表的分頁顯示,通過學(xué)習(xí),實(shí)現(xiàn)了用戶列表的分頁顯示,代碼如下:
app/index/controller/User.php
<?php namespace app\index\controller; use app\model\User as UserModel; use think\Controller; use think\Db; class User extends Controller { //顯示用戶信息 public function disUser($uid) { //分頁配置項(xiàng) $config=[ 'type'=>'bootstrap', 'var_page'=>'page' ]; //每頁數(shù)量 $num=3; //不要簡單分頁 $simple=false; //獲取所需要的分頁數(shù)據(jù) $paginate= UserModel::paginate($num, $simple, $config); //分頁變量 $page = $paginate->render(); $this->view->assign('users',$paginate); $this->view->assign('page',$page); return $this->view->fetch(); } }
app/view/user/dis_user.html
{load href="/static/css/bootstrap.min.css" /} <div class="container"> <div class="row"> <h3 class="text-center">日本女明星記錄表</h3> <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="users" id="user"} <tr> <td>{$user.uid}</td> <td>{$user.name}</td> <td> {between name="user.weight" value="60,90"} 普通尺寸 {/between} {between name="user.weight" value="91,100"} 較大 {/between} {between name="user.weight" value="101,150"} 超大 {/between} </td> <td>{$user.height}</td> <td>{$user.add_time|date="Y-m-d H:i:s"}</td> </tr> {/volist} </table> <div class="text-center">{$page|raw}</div> </div> </div> </div>
app/model/user.php
<?php namespace app\model; use think\Model; use think\model\concern\SoftDelete; class User extends Model { //引用軟刪除的trait方法集 use SoftDelete; //表名 protected $table='user'; //主鍵 protected $pk='uid'; //設(shè)置刪除時間字段,供軟刪除使用 protected $deleteTime='delete_time'; //設(shè)置軟刪除默認(rèn)值 protected $defaultSoftDelete=0; //region 獲取器 //獲取性別 protected function getSexAttr($value,$data) { $sex=[0=>'男',1=>'女']; return '我叫:'.$data['name'].',我是'.$sex[$value].'生'; } //獲取自定義屬性 protected function getMsgAttr($value,$data) { return '本女'.$data['name'].',胸圍'.$data['weight']; } //#endregion //region 修改器 //自動轉(zhuǎn)換日期格式成時間戳 protected function setAddTimeAttr($value) { return strtotime($value); } //胸圍更改時自動加1 protected function setWeightAttr($value,$data) { return $value+1; } //endregion //開啟當(dāng)前模型的自動時間戳功能 protected $autoWriteTimestamp = true; //設(shè)置支持自動時間戳功能的字段名 protected $createTime = 'create_time'; protected $updateTime = 'modify_time'; //類型轉(zhuǎn)換 protected $type=[ 'sex'=>'integer', 'weight'=>'integer', 'height'=>'integer', ]; //自動完成 protected $insert=['sex'=>1]; protected $update=['sex'=>0]; protected $auto=['height'=>'160']; }
效果圖:
批改老師:查無此人批改時間:2019-04-23 13:41:23
老師總結(jié):完成的不錯。頁面分頁是tp框架里的,可以做成公用的,直接調(diào)用就可以了。繼續(xù)加油。