* [ ] Model 文件的作用
* 集中管理各表的操作,控制層調用 Model 方法,控制層返回結果
* 避免在控制器里面直接寫操作表,加入數據表名因為某種原因,名字變了,那么改動的地方特別多
* 當然根據個人喜好,選擇不同的操作方式
* [ ] 場景
* 假設操作 user 數據庫的 user_account 表
* 假設項目里面存在操作多個數據庫,那么操作每個表的 Model 文件存儲路徑為:
* /home/wwwroot/project/appliction/lib/model/User/AccountModel.php
* 命名規則:/home/wwwroot/project/appliction/lib/model/[數據庫名(和數據庫中間類名一致)]/[不帶表前綴的名稱,首字母大寫]Model.php
* 實例代碼:
~~~
<?php
namespace model\User;
use model\Common\CurdTrait;
use model\Common\PublicModel;
/**
* 用戶管理
* Class AccountModel
* @package model\User
*/
class AccountModel extends PublicModel
{
use CurdTrait;
// 操作的數據庫
protected static $dbObj = 'User';
// 操作的表名,不帶表前綴
protected static $tabName = 'account';
// [如果沒有,設置為空字符] 該表的主鍵
protected static $tabId = 'uid';
// 簡單的Demo
public static function getUserInfo( $uids = [] )
{
if ( empty($uids) )
{
return [];
}
$where = array(
'uid[in]' => $uids,
);
$user_infos = self::select($where);
return $user_infos;
}
}
~~~
- 開始使用
- 配置文件
- 路由模式
- AutoLoad類
- 啟動文件
- __construct
- SetRouting
- SetAlias
- SetStop
- SetError
- Access
- SetWorker
- SetClassFile
- SetClassDir
- Run
- OpenLoad
- LinuxStartAll
- Session類
- 使用說明
- set
- get
- delete
- pull
- has
- id
- Cookie類
- 使用說明
- set
- get
- delete
- pull
- has
- TempLets類
- 模板語法
- 模板標簽
- html
- show
- assign
- obtain
- Request類
- get
- post
- host
- referer
- getip
- localip
- header
- body
- file
- scheme
- protocolversion
- uri
- path
- querystring
- method
- Response
- SendFile
- FileStream
- SendData
- SetStatus
- SetHead
- SetMime
- WebSend
- redirect
- dumpJson
- dump
- come
- ps
- Frame類
- GetWeb
- ViewFile
- RoutingData
- SetClassFile
- SetClassDir
- GetMime
- FileMime
- LoadDir
- StartDir
- IsJson
- ArrJson
- JsonFormat
- ObStart
- GetConfig
- ConfigDir
- TempDir
- GetRunData
- GetStatic
- IsDebug
- SetDebug
- GetDebugInfo
- GlobalVariables類
- 使用說明
- set
- get
- delete
- pull
- has
- id
- Mysql類
- 新版本
- 第三方
- Thinkorm
- Medoo
- 舊版本
- Mysql 配置格式
- 項目中操作數據庫
- 項目場景
- 項目數據庫配置
- 項目數據庫中間類
- 項目中操作數據表
- 連貫操作
- where
- table
- data
- order
- field
- limit
- page
- group
- having
- join
- tabname
- union
- sql
- link
- link_base
- lock
- CURD 操作
- 寫入數據
- 數據刪除
- 數據查詢
- 數據更新
- 數據統計操作
- count
- sum
- max
- min
- avg
- 操作DEMO
- CurdTrait.php
- 項目Model層操作表.md
- Curl類
- Method類
- SslAes類
- layui_zqadmin