<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 一、列表答疑 **(1)為什么控制器繼承了應用基礎控制器后我們可以直接使用$this->dataList() ?** 因為應用基礎控制器繼承了BaseLikeShopController,而BaseLikeShopController中存在dataLists方法,所以只要我們自己的控制器繼承了應用基礎控制器就可以直接調用該方法。 **(2)調用了$this->dataList()方法就能馬上得到數據嗎?還要做什么?** 不會馬上得到數據,還要創建相應的列表類。原因可從dataLists()這個方法的實現中可以看出: 調用方法不傳參數,需創建以當前控制器名+Lists的列表類 調用方法傳了指定列表類實例,實現指定列表類即可 列表類通常存放于當前應用的 lists目錄中 **(3)列表請求方式必須是GET嗎**?是的! (4) 特別注意: 分頁改為用limit()方法,不要再使用page()** 原因:底層導出功能設計需要limit()支持,而page()無法滿足需求 前端傳遞分頁參數不變,仍然是 page_no/page_size, 底層會自動獲取前端分頁參數并計算出$this->limitOffset, $this->limitLength的值 ``` limit($this->limitOffset, $this->limitLength) ``` **(5)參考例子: 文章列表類** ``` <?php namespace app\adminapi\lists; use app\common\lists\ListsSearchInterface; use app\common\model\Article; class ArticleLists extends BaseAdminDataLists implements ListsSearchInterface { /** * @notes 設置搜索 * @return \string[][] * @author Tab * @date 2021/7/14 9:48 */ public function setSearch() : array { return [ '=' => ['type', 'cid', 'is_notice'], '%like%' => ['title'] ]; } /** * @notes 文章/幫助列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Tab * @date 2021/7/14 9:48 */ public function lists() : array { $lists = Article::field('id,title,image,cid,is_notice,is_show,visit,likes,sort,create_time') ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); return $lists; } /** * @notes 文章/幫助總記錄數 * @return int * @author Tab * @date 2021/7/14 9:48 */ public function count() : int { return Article::where($this->searchWhere)->count(); } } ``` ### 二、搜索接口使用 **(1) 須實現`ListsSearchInterface`接口,該接口包含一個需要實現的`setSearch()`**,該方法用于設置搜索條件 ``` public function setSearch() : array { return [ '=' => ['type', 'cid'], '%like%' => ['title'] ]; } ``` **(2) 組裝后的搜索條件通過!!#ff0000 $this->searchWhere!!屬性接收** 具體組裝邏輯可參考:app/common/lists/ListsSearchTrait.php 多個條件關系是: and關系 例 : 前端傳過來的值 type = 1, cid = 10 后端:['=' =>[ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '=', '1'], ['cid', '=', '10'] ] 后端:['<>' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '<>', '1'], ['cid', '<>', '10'] ] 后端:['>' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '>', '1'], ['cid', '>', '10'] ] 后端:['>=' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '>=', '1'], ['cid', '>=', '10'] ] 后端:['<' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '<', '1'], ['cid', '<', '10'] ] 后端:['<=' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', '<=', '1'], ['cid', '<=', '10'] ] 后端:['in' => [ 'type', 'cid']] 組裝后生成 $this->searchWhere = [ ['type', 'in', '1'], ['cid', 'in', '10'] ] 例 : 前端傳過來的值 name = 好象 后端:['%like%' => ['name']] 組裝后生成 $this->searchWhere = [ 'name', 'like', '%好象%' ] 后端:['%like' => ['name']] 組裝后生成 $this->searchWhere = [ 'name', 'like', '%好象' ] 后端:['like%' => ['name']] 組裝后生成 $this->searchWhere = [ 'name', 'like', '好象%' ] 例 : 前端傳過來的值 start_time = 2021-07-01 end_time = 2021-07-31 后端:['between_time' => 'create_time'] 組裝后生成 $this->searchWhere = [ 'create_time', 'between', [66666666,88888888]] 注:66666666對應的是2021-07-01的時間戳,88888888對應的是2021-07-01的時間戳 例 : 前端傳過來的值 start = 10 end = 100 后端:['between' => 'sort'] 組裝后生成 $this->searchWhere = [ 'sort', 'between', [10,100]] **例:支持別名** 后端:['=' => [ 'a.type', 'a.cid']] 組裝后生成 $this->searchWhere = [ ['a.type', '=', '1'], ['a.cid', '=', '10'] ] **(3) 使用參考 ** Admin::where(!!#ff0000 $this->searchWhere!!)->select(); **(4)、更復雜的條件** 若setSearch()方法中無法實現的搜索條件,可不實現搜索接口,在lists()及count()方法中自行定義自己需要的搜索條件即可 ``` public function lists() : array { // $where[] = [xxx,xxx,xx]; 這里疊加自已搜索條件 $lists = Footprint::where($where)->select()->toArray(); return $lists; } public function count() : int { // $where[] = [xxx,xxx,xx]; 這里疊加自已搜索條件 return Footprint::where( $where)->count(); } ``` ### 三、排序接口使用 **(1) 列表須實現`ListsSortInterface`接口,該接口中包含兩個需要實現的方法`setSortFields()`、`setDefaultOrder()`** `setSortFields()` 設置允許的排序字段,例: ``` public function setSortFields(): array { // 格式: ['前端傳過來的字段名' => '數據庫中的字段名']; // 前端傳過來create_time,后端會根據create_time排序 // 前端傳過來id,但后端會根據user_id排序 return ['create_time' => 'create_time','id'=>'user_id']; } ``` `setDefaultOrder()` 設置默認排序規則 什么情況下會使用默認排序: 1.1、前端未傳排序字段 field時 1.2、前端未傳排序規則 order_by時 1.3、后端setSortFileds()方法返回 空數組時 1.4、前端傳過來的排序字段不在允許的排序字段中時,例:前端傳過來排序字段money, 但允許的排序字段數組 ['create_time' => 'create_time'] 中并沒有money這個字段 1.5、允許排序字段格式設置不正確時,例: ['create_time' => 'create_time'] 設置成了 ['create_time'] ``` public function setDefaultOrder(): array { return ['id' => 'desc']; } ``` **(2) 前端必須傳的兩個參數** order_by排序規則(desc-倒序 asc-升序) ,field排序字段 **(3) 后端組裝后的排序規則通過 $this->sortOrder屬性接收** 具本的排序組裝邏輯請參考: app/common/lists/ListsSortTrait.php 例:前端傳 { order_by: desc, field: create_time } 后端:$this->sortOrder = [‘create_time’ => ‘desc’]; 前端傳 { order_by: desc, field: id } 后端:$this->sortOrder = [‘user_id’ => ‘desc’]; 前端不傳排序相關參數 或 符合設置默認排序中說明的情況時 后端:$this->sortOrder = [‘id’ => ‘desc’]; **(4) 使用參考 ** Admin::order(!!#ff0000 $this->sortOrder!!)->select();
                  <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>

                              哎呀哎呀视频在线观看