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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 分頁 Page 分頁是在進行列表 List 查詢過程中,基本都會使用到,為了更加快速的進行產品開發,我們對分頁操作進行了封裝,并且繼承了 ThinkPHP 原生的 Page.class.php 類庫,封裝了分頁調用函數。 **位置:**Application\Common\Common\function.php **參數:** > * @param int $count 要分頁的總記錄數 > * @param int $pagesize 每頁查詢條數 **調用:** > $page = getpage($count, 10); // 調用分頁函數 > limit($page->firstRow.','.$page->listRows) // 傳值分頁搜索 > $this->assign('page', $page->showFront()); // 分頁賦值模版 **實例:** 1、Controller 控制器的方法中: ~~~ $count = M('system_log')->count(); // 統計數量 $page = getpage($count, 10); // 調用分頁函數,Param總數,每一頁顯示10條 $log_list = M('system_log') ->limit($page->firstRow.','.$page->listRows) // 傳值分頁搜索 ->select(); $this->assign('log_list', $log_list); $this->assign('page', $page->showFront()); // 分頁賦值模版 $this->display(); ~~~ 2、View 模版賦值 ~~~ <volist name="log_list" id="vo"> <tr> <td>{$vo.id}</td> <td>{$vo.nickname}</td> </tr> </volist> {$page} <!-- 調用分頁 --> ~~~ 在需要調用的分頁位置,一般在列表 List 下面 * * * * * **帶搜索的分頁實例:** 在進行列表分頁的時候,經常會用到多個搜索條件的列表,而且要進行分頁,下面實例講到具體的使用和調用 1、搜索分頁第一步是進行條件的搜索,搜索 Form 的提交方式我們一般選擇 GET,POST 也可以,而 GET 我們可以在 URL 更完成的看到搜索的條件的傳值,更有利于分頁的調試,那么約定好搜索就使用 GET 方式傳值,其他的寫法都沒什么區別,**分頁方法會自動取值并賦值在分頁的 URL 上面進行分頁**。 搜索的URL: > index?user_id=17 // 傳值 user_id 分頁后的URL > index/user_id/17/p/2.html // 分頁帶出 user_id 2、多選條件的搜索分頁 在進行 Select 多選和 Input checkbox 多選框等的搜索的時候,后臺接收的數據會是一個數組,那該怎么在分頁進行傳值呢? > array (size=3) > 0 => string 'banana' > 1 => string 'grape' > 2 => string 'mango' 為了解決多選數據是數組的問題,在封裝的函數里面將數組自動判斷轉換成用“-” 符號連接的字符串,在賦值在分頁的URL上面 > index/name/banana-grape-mango/p/2.html 而在后臺取數據的時候,**提交 Form 表單的時候獲取的 $name 是一個數組,在分頁的時候獲取的 $name 是一個字符串**,需要將字符串進行轉換為數組 ~~~ $name = I('param.name'); if(!is_array($name)) { $name = explode("-", $name); // 拆分字符串為數組 } ~~~ **完整代碼:** ~~~ // 調用 Think Page 的分頁 /* * @param int $count 要分頁的總記錄數 * @param int $pagesize 每頁查詢條數 * @return \Think\Page */ function getpage($count, $pagesize = 10){ $p = new Think\Page($count,$pagesize); $p->lastSuffix = false; $p->setConfig('prev','上一頁'); $p->setConfig('next','下一頁'); $p->setConfig('last','尾頁'); $p->setConfig('first','首頁'); $p->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%'); $arr_input = I('param.'); // 獲取 input 搜索表單數據 foreach($arr_input as $key => $val) { if (is_array($val)) { // 如果是數組拆分成連接字符串 $str = ''; foreach ($val as $k => $v) { $str = $str . '-' . $v; } $val = substr($str,1,strlen($str)); // 去掉第一個字符 - } $p->parameter[$key] = $val; } return $p; } ~~~ **重寫的 page.class.php 類的 show 方法:** ~~~ /** * [showFront 前端分頁樣式] * @return [string] [組裝好的鏈接] */ public function showFront() { $this->config['header'] = '<li><span class="rows">%NOW_PAGE% / %TOTAL_ROW% 條記錄</span></li>'; $this->config['prev'] = "上一頁"; $this->config['next'] = "下一頁"; $this->rollPage = 4; if(0 == $this->totalRows) return ''; /* 生成URL */ $this->parameter[$this->p] = '[PAGE]'; $this->url = U(ACTION_NAME, $this->parameter); /* 計算分頁信息 */ $this->totalPages = ceil($this->totalRows / $this->listRows); //總頁數 if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) { $this->nowPage = $this->totalPages; } /* 計算分頁零時變量 */ $now_cool_page = $this->rollPage/2; $now_cool_page_ceil = ceil($now_cool_page); $this->lastSuffix && $this->config['last'] = $this->totalPages; //上一頁 $up_row = $this->nowPage - 1; $up_page = $up_row > 0 ? '<li><a href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a></li>' : ''; //下一頁 $down_row = $this->nowPage + 1; $down_page = ($down_row <= $this->totalPages) ? '<li> <a href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a> </li>' : ''; //第一頁 $the_first = ''; if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){ $the_first = '<li><a href="' . $this->url(1) . '">' . $this->config['first'] . '</a></li>'; } //最后一頁 $the_end = ''; if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){ $the_end = '<li><a href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a></li>'; } //數字連接 $link_page = ""; for($i = 1; $i <= $this->rollPage; $i++){ if(($this->nowPage - $now_cool_page) <= 0 ){ $page = $i; }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){ $page = $this->totalPages - $this->rollPage + $i; }else{ $page = $this->nowPage - $now_cool_page_ceil + $i; } if($page > 0 && $page != $this->nowPage){ if($page <= $this->totalPages){ $link_page .= '<li><a href="' . $this->url($page) . '">' . $page . '</a></li>'; }else{ break; } }else{ if($page > 0 && $this->totalPages != 1){ $link_page .= '<li><span class="current">' . $page . '</span></li>'; } } } //替換分頁內容 $page_str = str_replace( array('%UP_PAGE%', '%HEADER%', '%NOW_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'), array( $up_page, $this->config['header'], $this->nowPage, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages ), $this->config['theme']); // return "{$page_str}"; 底下是重寫的分頁樣式 2016-12-26 jig update $result = '<div class="col-xs-4"> <div class="page-num">共' . $this->totalPages . '頁' . $this->totalRows . '條數據</div> </div> <div class="col-xs-8"> <div class="erppagination2"> <ul class="pagination pagination-sm" style="margin-top:0;">'. $page_str .'</ul> </div> </div>'; return $result; } ~~~
                  <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>

                              哎呀哎呀视频在线观看