懶人后臺控制器
```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"></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"></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>
```
- 課程介紹
- thinkphp5.0
- 安裝
- 開發規范
- 目錄結構
- 配置參數
- 系統常量
- tp5自帶的函數
- 助手函數
- 擴展類庫
- 基本類庫
- Workerman
- think-queue
- 驗證碼
- 圖片
- 權限認證
- 課前準備
- 數據庫設計
- 模塊設計
- 管理員管理
- 添加
- 編輯
- 刪除和批量刪除
- 列表頁
- 實列
- 權限管理
- 操作日志
- 基于行為的日記錄
- 行為日志的擴展
- 助手類庫
- 自建函數
- 將數組轉成uri字符串
- 獲取當前服務器的IP
- curl-post
- 截取文字中間的字符串
- 檢查中文姓名
- 省市區分別截取
- 抽獎概率問題
- 短信郵箱模板替換
- 生成csv
- PHP 圖片轉base64
- 銀行卡驗證
- json返回接口封裝
- 無限極分類
- 病毒
- xml和數組互轉
- xml轉成數組
- 數組轉xml
- tp控制器相關
- 獲取thinkph5下控制器和方法名
- 后臺查詢的簡單封裝
- 網址信息
- 獲取網站logo
- 判斷url是否存在
- 獲取title
- 判斷遠程文件是否存在
- 獲取頁面所有鏈接
- 過濾
- 截取
- 時間
- 獲取服務器信息
- 根據id生成唯一邀請碼
- 隨機顏色
- 數組字符串互換
- 創建多級目錄
- 懶人查詢
- 時間和時間戳轉換
- 房間id生菜
- 獲取需要的數組元素
- 文件和文件夾
- 文件類庫
- 文件夾
- 七牛云
- 七牛云運用場景
- 七牛云使用實例
- 郵箱
- 郵箱驗證
- 郵箱發送
- 數據庫
- 數據庫在thinkphp中的補充方法
- 備份和安全
- sql執行
- 數據庫備份2
- 時間日歷
- 時間格式化
- 日歷
- 圖片相關
- 自動獲取圖片主題顏色
- 獲取html中的圖片路徑
- 獲取圖片場景
- 獲取圖片實踐
- 圖片處理類
- 圖片處理場景
- 圖片處理實踐
- 數據驗證分析
- 身份證相關
- 新聞
- 自建類庫
- 簡易分類庫
- php 壓縮CSS代碼
- 身份證
- 分詞和抽詞
- 分詞應用場景
- 分詞實踐
- 中文轉拼音
- 中文轉拼音場景
- 中文轉拼音實踐
- 二維碼操作
- 二維碼場景
- 二維碼實踐
- 短地址
- PHPWord
- 插件化
- 插件擴展庫
- 插件列表
- 插件安裝和卸載
- 插件實踐
- 插件的離線安裝
- 計劃任務
- 計劃任務安裝
- 計劃任務實踐
- 定時器
- 注冊登錄
- 普通登錄注冊
- 第三方登錄注冊
- jwt接口登錄注冊
- 短信
- 飛鴿短信
- 阿里短信
- 消息隊列
- 網站地圖
- 全站靜態化
- 緩存
- 文件導出
- PDF生成
- phpword
- PHPExcel
- 其他類庫
- 百度
- 百度語音
- 快遞
- 跨域問題
- 寶塔
- 搜索記錄