企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
懒人后台控制器 ```php protected function _initialize() { parent::_initialize(); // TODO: Change the autogenerated stub $this->mod = Db::name("website"); $this->modname ="website"; $selectfe=[ "id"=>"代码id", "name"=>"代码名称", "sorting"=>"排序", ]; $wherefe=[ "id"=>"代码id", "name"=>"代码名称", "sorting"=>"排序", ]; $user = session("merchant"); $this->assign('user', $user); $this->assign('wherefe', $wherefe); $this->assign('selectfe', $selectfe); $this->assign('add', "/admin/sucai.sucai/add.html"); $this->assign('edit', "/admin/sucai.sucai/edit"); $this->assign('del', "/admin/sucai.sucai/del.html"); } //列表 admin/sucai.SucaiCat/index public function index() { $where=[]; if ($this->request->isPost()) { //array("name"=>[expr,val]) // dump( $this->request->param( ));die; $where = wheres($this->request->param( )); //array("name"=>[expr,val]) // var_dump($where);die; } $user = session("merchant"); //var_dump($user);die; $total = $this->mod ->where($where) ->count(); $list = $this->mod ->where($where) ->paginate(10,true,[ 'type' => 'bootstrap', 'var_page' => 'page', ]); // 获取分页显示 $page = $list->render(); // var_dump( $list);die; // 模板变量赋值 $this->assign('page', $page);; $this->assign("rows", $list); $this->assign("total", $total); return $this->view->fetch(); } ``` where方法 ```php // 详细查询 //expr,val function wheres($where){ $returnwhere=[]; if(isset($where)&&!empty($where)&&is_array($where)){ foreach($where as $key=>$val ){ if(!empty($val["val"])){ if(strtoupper(trim($val["expr"]))=="LIKE"){ //模糊查询 $returnwhere[$key]=[trim(trim($val["expr"])),"%".$val["val"]."%"]; }else if(strtoupper(trim($val["expr"]))=="BETWEEN"||strtoupper(trim($val["expr"]))=="NOT BETWEEN"){ //区间查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="IN"||strtoupper(trim($val["expr"]))=="NOT IN"){ //IN查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="NULL"||strtoupper(trim($val["expr"]))=="NOT NULL"){ //NULL查询 $returnwhere[$key]=$val["expr"]; }else if(strtoupper(trim($val["expr"]))=="EQ"||strtoupper(trim($val["expr"]))=="="){ //EQ查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="NEQ"||strtoupper(trim($val["expr"]))=="<>"){ //NEQ查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="GT"||strtoupper(trim($val["expr"]))==">"){ //GT查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="EGT"||strtoupper(trim($val["expr"]))==">="){ //EGT查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="LT"||strtoupper(trim($val["expr"]))=="<"){ //LT查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; }else if(strtoupper(trim($val["expr"]))=="ELT"||strtoupper(trim($val["expr"]))=="<="){ //ELT查询 $returnwhere[$key]=[trim($val["expr"]),$val["val"]]; } } } } //var_dump(trim($val["expr"]),strtoupper(trim($val["expr"])));die; return $returnwhere; } ``` 懒人后台列表页面 ```html <form class="layui-form layui-col-md12 x-so" method="POST"> {foreach name="wherefe" item="vose" key="key"} <div class="row"> <input type="text" name="{$key}[val]" placeholder="{$vose}" id="{$key}[val]"> <input type="hidden" name="{$key}[expr]" value="=" id="{$key}[expr]"> </div> {/foreach} <div class="rowz"> <input type="submit" value="Submit"> </div> </form> <table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center"> <thead> <tr> <th> <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div> </th> {foreach name="selectfe" item="vose" key="key"} <th>{$vose}</th> {/foreach} <!-- <th>广告id</th> <th>广告名称</th> <th>链接地址</th> <th>广告位置名称</th> --> <th >操作</th> </tr> </thead> <tbody> {volist name="rows" id="vo"} <tr> <td> <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div> </td> {foreach name="selectfe" item="vose" key="key"} <td> {$vo[$key]}</td> {/foreach} <td class="td-manage"> <button class="button buttonbor2" style="padding:3px" onclick="x_edit_show('编辑','{$edit}/id/'+{$vo['id']})">修改</button> <button class="button buttonbor3" style="padding:3px" onclick="x_del(this,'要删除的id')">删除</button> </td> </tr> {/volist} </tbody> </table> <div class="pagination3"> {$page} <div> ```