thinkphp5.1與layui table表格使用


第1部分:layui 的 html代碼,

即第2部分 thinkphp 控制器方法 index/Dataz/returnShowUser 的view頁面

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>table模塊快速使用</title>
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>
 
<table id="demo" lay-filter="test"></table>
 
<script src="/layuiadmin/layui/layui.js"></script>
<script>
layui.use('table', function(){
  var table = layui.table;
  
  //第一個實例
  table.render({
    elem: '#demo'
    ,height: 312
    ,url: '{:url('index/Dataz/index')}' //數據接口
    ,page: true //開啟分頁
    ,limit:6
    ,cellMinWidth: 30
    ,cols: [[ //表頭
      {field: 'id', title: 'ID', sort: true, fixed: 'left'}
      ,{field: 'username', title: '用戶名'}
      ,{field: 'create_time', title: '創建時間', sort: true}
      ,{field: 'email', title: '郵箱'} 
      ,{field: 'phone', title: '手機'}
      ,{field: 'face_img', title: '頭像地址',}
      ,{field: 'userip', title: 'IP', sort: true}
      ,{field: 'status', title: '狀態', }
      ,{field: 'update_time', title: '更新時間', sort: true}
    ]]
  });
  
});
</script>
</body>
</html>

 

第2部分:thinkphp 控制器 方法

<?php
namespace app\index\controller;
use think\Controller;
use \app\common\model\Useradmin as Useradmin;

class Dataz extends Controller
{
    public function index()
    {

        //獲得數據總數
        $useradmin = new Useradmin();
        $user = $useradmin->order('id','asc')->select();
        $allcount = count($user);
        
        //獲取傳遞的分頁參數
        $page=request()->param('page');
        $limit=request()->param('limit');
        $start=$limit*($page-1);

        //分頁查詢
        $userpage = $useradmin->order('id','asc')->limit($start,$limit)->select();
        $res = [
                    'code'=>0,
                    'msg'=>'返回成功',
                    'count'=>$allcount,
                    'data'=>$userpage
                ];
        return json($res);
    }

    public function returnShowUser(){
        return view('index');
    }
 
}

 

第3部分:完成預覽,訪問{:url('index/Dataz/returnShowUser')}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM