亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

分頁(yè)顯示的用戶(hù)信息列表

asal 2019-05-16 00:22:26 303
abstrak:1.控制器類(lèi)代碼<?phpnamespace app\index\controller;use think\Controller;use app\index\model\Staff as StaffModel;use think\facade\Request;use think\Paginator;class Staff extends Controller{    //

1.控制器類(lèi)代碼

<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Staff as StaffModel;
use think\facade\Request;
use think\Paginator;

class Staff extends Controller
{
   //循環(huán)標(biāo)簽
   public function demo1()
   {
       $staffs = StaffModel::all(function ($query) {
           $query->field(['id', 'name', 'sex', 'age', 'salary']);
           // ->where('salary','<',100);
       });
//    $this->view->assign('staffs', $staffs);
       return $this->view->fetch();
   }
   //分頁(yè)查詢(xún)
  public function demo2()
  {
     //分頁(yè)配置
     $config = [
        'type' => 'bootstrap',
        'var_page' => 'page',
     ];
     //每頁(yè)數(shù)量
     $num = 5;
     //是否是簡(jiǎn)單分頁(yè)
     $simple = false;
     //獲取所有分頁(yè)數(shù)據(jù):返回值是分頁(yè)對(duì)象: think\Paginate
     $paginate = StaffModel::paginate($num, $simple, $config);
     //渲染分頁(yè)的HTML,返回分頁(yè)變量
     $page = $paginate->render();
     //將分頁(yè)對(duì)象賦值給模板
     $this->view->assign('staffs', $paginate);
     //將分頁(yè)變量賦值給模板
     $this->view->assign('page', $page);
     //渲染模板
     return $this->view->fetch();
  }
}

2.模板類(lèi)

<?php
namespace app\index\model;
use think\Model;  //Model沒(méi)有Facade

class Staff extends Model
{
  protected $table = 'staff';
  protected $pk = 'id';
}

3.視圖類(lèi)

{load href="/static/bootstrap/css/bootstrap.css" /}

<div class="container">
  <div class="row">
     <h3 class="text-center">用戶(hù)信息登記錄</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>手機(jī)</td>
           </tr>
           {empty name="staffs"}
              <h3 style="color: red;">當(dāng)前沒(méi)有符合條件的數(shù)據(jù),請(qǐng)檢查~~</h3>
           {else /}
           {volist name="staffs" id="staff"}
           <tr>
              <td>{$staff.id}</td>
              <td>{$staff.name}</td>
              <td>
              {//$staff.sex}
              {//性別必須是0或1,才是合法數(shù)據(jù)}
              {in name="staff.sex" value="0,1"}
                 {if $staff.sex == 0}
                    男
                 {else /}
                    女
                 {/if}
              {/in}
              </td>
              <td>{$staff.age}</td>
              <td>{$staff.mobile}</td>
           </tr>
           {/volist}
           {/empty}
        </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" /}

4.運(yùn)行效果圖

QQ圖片20190516002034.png

Guru membetulkan:查無(wú)此人Masa pembetulan:2019-05-16 09:39:53
Rumusan guru:完成的不錯(cuò),tp框架多看看文檔。前端頁(yè)面盡量少點(diǎn)邏輯,php多做邏輯處理。繼續(xù)加油。

Nota Keluaran

Penyertaan Popular