thinkphp自訂分頁效果

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   strong   io   

TP內建了一個分頁函數,挺方便使用的。

下面是我的使用方法:

 1 /*****************分頁顯示start*************************/ 2            $arr_page=$this->page($user,1); 3            $show=$arr_page[‘show‘]; 4            $Page=$arr_page[‘Page‘]; 5         $article = $user->order(‘now‘)->limit($Page->firstRow.‘,‘.$Page->listRows)->select(); 6         if(!empty($_POST[‘seach_classify‘])){ 7             $seach_classify=$_POST[‘seach_classify‘]; 8             $arr_page=$this->page($user,1,"classify=‘$seach_classify‘"); 9                $show=$arr_page[‘show‘];10                $Page=$arr_page[‘Page‘];11                $Page->setconfig("prev","上");12 13             dump($Page);     14             $article=$user->order("now")->limit($Page->first.‘,‘.$Page->prev)->where("classify=‘$seach_classify‘")->select();15         }16         //dump($list);17 /*****************分頁顯示end************************/

結合自己封裝的一個分頁函數:

 public function page($db,$num,$where){        $count = $db->where($where)->count();//         $Page       = new \Think\Page($count,$num);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數(25)        $show       = $Page->show();// 分頁顯示輸出        return $arr_page = array(            "show"=>$show,            "Page"=>$Page,            "count"=>$count,            );            }

即可實現查詢和按條件查詢分頁,這裡的按條件查詢分頁,雖然能差出資料,但再點擊查詢的分頁連結就返回原來的無條件查詢了,

我這裡判斷的是$_POST[‘seach_classify‘]不為空白才查詢,不過可以理解,如果點擊了查詢分頁連結,頁面會重新整理,$_POST[‘seach_classify‘]就返回是空的了,

現在還想不出解決辦法,望高手解答!

下面是我自訂的分頁效果製作:

需要修改底層的thinkphp/Library/Think/Page.class.php,修改如下:

1 // 分頁顯示定製2     private $config  = array(3         ‘header‘ => ‘<span class="rows">共 %TOTAL_ROW% 篇文章</span>‘,//可以直接修改這裡,也可以在你的方法裡面設定$page->setconfig("header","篇文章")4         ‘prev‘   => ‘上一頁‘,//這裡同上5         ‘next‘   => ‘下一頁‘,6         ‘first‘  => ‘返回首頁‘,7         ‘last‘   => ‘...%TOTAL_PAGE%‘,8         ‘theme‘  => ‘%FIRST% %LINK_PAGE% %HEADER% %END%‘,//這裡自訂你的分頁輸出內容,內容在下面9     );
1  //替換分頁內容2         $page_str = str_replace(3             array(‘%HEADER%‘, ‘%NOW_PAGE%‘, ‘%UP_PAGE%‘, ‘%DOWN_PAGE%‘, ‘%FIRST%‘, ‘%LINK_PAGE%‘, ‘%END%‘, ‘%TOTAL_ROW%‘, ),//這裡是自訂所需內容4             array($this->config[‘header‘], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),5             $this->config[‘theme‘]);6         return "{$page_str}";

下面是效果自訂:

 1 //數字串連 2         $link_page = ""; 3         for($i = 1; $i <= $this->rollPage; $i++){ 4             if(($this->nowPage - $now_cool_page) <= 0 ){ 5                 $page = $i; 6             }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){ 7                 $page = $this->totalPages - $this->rollPage + $i; 8             }else{ 9                 $page = $this->nowPage - $now_cool_page_ceil + $i;10             }11             if($page > 0 && $page != $this->nowPage){12 13                 if($page <= $this->totalPages){14                     $link_page .= ‘<a class="num" href="‘ . $this->url($page) . ‘"><div>‘ . $page . ‘</div></a>‘;//這裡的div我自己加的,以便用css定製效果!css見下面15                 }else{16                     break;17                 }18             }else{19                 if($page > 0 && $this->totalPages != 1){20                     $link_page .= ‘<span class="current"><div id="nowPage">‘ . $page . ‘</div></span>‘;21                 }22             }23         }

css:

div.fenye{background:; text-align:center; width:800px;margin:15px -400px 0 0; right:50%; position:absolute; box-shadow:0 0 5px #888;}div.fenye div{transition:background 0.5s,box-shadow 1s; text-align:center; width:40px; height:25px; float:left;color:#FFF}div.fenye div:hover{background:#FFF; text-align:center; float:left; color:#000;box-shadow:0 0px 15px #FFF;}div#nowPage{box-shadow:0 0px 15px #FFF;color:#000;background:#FFF;}span.rows{color:#666;};

 

:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.