官方例子:https://www.layui.com/doc/modules/table.html#methodRender
一、模板
优惠券
请选择搜索类型
标题
搜索
二、控制器 数据 ,url: '{:url('index')}?action=usertable'
$action=input('action');
$sotitle=input('sotitle');
$sotype=input('sotype');
$limit=input('limit');
$limit=$limit?$limit:10;
$this->assign('sotype',$sotype);
$page=input('page');//页数
$starttime=input('starttime');//创建开始时间
$enttime=input('enttime');//创建结束时间
$field=input('field');//字段
$order=input('order');//排序方式
//排序
if($field){
$od=$field." ".$order;
}else{
$od="id desc";
}
$where['deleted'] = 0;//状态 0正常 1回收站
$rsu=Db::name('user')->where($where)->order($od)->limit($limit)->page($page)->select();
$rsu1=Db::name('user')->where($where)->select();
$count = count($rsu1);//取得记录集总条数
json(0,'数据返回成功',$count,$rsu);
return $data;
json函数
/**
* 格式函数 专门把数据录格式成为layui 数据表格的格式
*/
function json($code,$msg="",$count,$data=array()){
$result=array(
'code'=>$code,
'msg'=>$msg,
'count'=>$count,
'data'=>$data
);
//输出json
echo json_encode($result);
exit;
}