<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Dao * ## Dao定義 ### 目錄位于 ``` \app\common\dao ``` >具體dao下在分塊,根據具體邏輯功能不同劃分 dao位于數據模型model層與邏輯處理層repository之間,處理每個特定邏輯數據庫操作或有共性的查詢、操作等 每一個dao對應一個model,比如在\app\common\model下存在User模型,那么在\app\dao下必然存在一個UserDao,必需繼承baseDao并實現getModel方法,關聯一個model類 ``` protected function getModel(): string { return User::class; } ``` 一個dao操作一個model類,model也只能通過這個dao被使用,不允許跨dao調用以及夸層級調用model 完整定義一個dao ``` <?php namespace app\dao\user; use app\dao\BaseDao; use app\model\user\User; /** * 用戶 * Class UserDao * @package app\dao\user */ class UserDao extends BaseDao { protected function getModel(): string { return User::class; } //公共查詢列表 public function search(array $where) { return $this->getModel()->getDb()->where('id',$where['id']); } } ``` * ## 使用 repository->dao->model 都是單一對應 dao必需在對應的repository中調用,不能被其他repository或者dao調用 比如:UserDao 必然只能被UserServices 使用 repository中注入對應dao ``` public function __construct(UserDao $dao) { $this->dao = $dao; } ``` 在repository中使用 ``` $this->dao ``` 就可以直接調用dao中定義的查詢或者增刪改差邏輯,比如: ``` $this->dao->search(['is_del'=>0]); ``` repository完整使用: ``` namespace app\common\repositories\user; use app\common\dao\user\UserDao; class UserRepository extends BaseRepository { protected $dao; public function __construct(UserDao $dao) { $this->dao = $dao; } public function search(array $where, int $page, int $limit) { $query = $this->dao->search($where); $list = $query->page($page,$limit)->select(); $count =$query->count(); return compact('count','list'); } } ``` * ## baseDao介紹 baseDao中內置了一些常用查詢、聚合、添加、修改方法,如下: * @ get(int $id) 獲取一條數據(主鍵) 返回`find()`查詢結果集對象 * @ getWhere(array $where, string $field = '*', array $with = [])獲取一條數據(多條件) 返回`find()`查詢結果集對象 * @ selectWhere(array $where, string $field = '*')獲取一條數據(多條件) 返回`select()`查詢結果集對象 * @ getWith(int $id, array $with)獲取一條數據(關聯查詢) 返回`find()`結果,查詢結果集對象 * @ update($id, array $data) 修改數據 返回`update()`結果,影響數據條數 * @ updates($id,s array $data) 修改數據(多條數據) 返回`update()`結果,影響數據條數 * @ fieldExists($map, string $field = '') 查詢一條數據是否存在 返回`true|false` * @ getWhereCount(array $where = []) 獲取某些條件總數(復雜條件嵌套,可以是二位數組) 返回`count()`統計條數 * @ findOrCreate(array $where) 查詢某個數據是否存在,如果不存在就創建這條數據 返回`create()`結果,當前模型對象實例 * @ delete($id, ?string $key = null) 刪除 返回`delete()`結果 * @ create(array $data) 保存數據 返回`create()`結果,當前模型對象實例 * @ insertAll(array $data) 批量保存數據 返回`insertAll()`結果,添加數據條數 * @ getSearch(array $where) 搜索器,傳入where條件,在model中定義搜索器就可查詢 返回`select()`結果 * @ incField(int $id, string $field , $num = 1) 條件自增 返回`update()`結果 * @ decField(int $id, string $field , $num = 1)條件自減 返回`update()`結果
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看