thinkphp Paging Implementation

Source: Internet
Author: User
Tags copy count end prev query return shallow copy
TP3.2 Framework Manual, there is a data paging, but each time to write too much code, as well as Chinese settings, such as some trouble, as a program developers, it is necessary to organize the following:           First, paging method the replication code/** &NB sp;* TODO The same code encapsulation of the underlying paging, making the foreground code less  * @param $m model, reference delivery  * @param $where query criteria  * @param int $pagesize The number of query bars per page &n bsp;* @return \think\page  */function getpage (& $m, $where, $pagesize =10) {    $m 1=clone $m;//Shallow copy a model & nbsp   $count = $m->where ($where)->count ();//The JOIN operation will be reset     $m = $m 1;//for the constant operation of the connection, a shallow copy of the model     $p =new think\page ($count, $pagesize);     $p->lastsuffix=false;     $p->setconfig (' header ', ' <li class= ' rows ' > Total <b>%TOTAL_ROW%</b> records    per page <b>%LIST_ROW%</b>    page <b>%NOW_PAGE%</b>/Total <b>%TOTAL_PAGE%</b> page </li> ');     $p->setconfig (' prev ', ' prev ');     $p->setconfig (' Next ', ' next page ');     $p->setconfig (' Last ', ' End ');     $p->setconfig (' first ', ' home ');   &NBSP $p->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end% ');       $p->parameter=i (' Get. ');       $m->limit ($p->firstrow, $p->listrows);       return $p; The copy code GetPage method can be placed in the application/common/common/of the TP framework function.php, this document can be dedicated to a number of common methods, where all can be invoked (such as: Controller file, view file, etc.).       II, paging method   $m =m (' products '); $p =getpage ($m, $where, 10); $list = $m->field (True)->where ($where)->order (' id desc ')->select (); $this->list= $list; $this->page= $p->show (); Again the View Code   &LT;DIV class= "pagination" > {$page} </div>     Three, the last is the style of pagination, this is a bit messy, because the background frame online download, Style has not come and finishing, this style can also be achieved, simple.   Copy code. Pagination UL     Display:inline-block     margin-bottom:0     Margin-lef t:0;    -WEBKIT-BORDER-RADIUS:3PX;    -MOZ-BORDER-RADIUS:3PX;     BORDER-RADIUS:3PX;    -webkit-box-shadow:0 1px 2px rgba (0, 0,0,0.05);    -moz-box-shadow:0 1px 2px rgba (0,0,0,0.05);     box-shadow:0 1px 2px rgba (0,0,0,0.05); }. Pagination ul li {  display:inline;}   pagination ul li.rows {    line-height:30px;   &N Bsp padding-left:5px; Pagination ul li.rows B{color: #f00}   Pagination ul Li A,. Pagination ul Li span {    float:left; &n Bsp   PADDING:4PX 12px;     line-height:20px;     Text-decoration:none;     Background-color: #fff;     Background:url ('.. /images/bottom_bg.png ') 0px 0px;     BORDER:1PX solid #d3dbde;    /*border-left-width:0;*/    margin-left:2px;     color: #08c; Pagination ul Li a:hover{    color:red     background: #0088cc; pagination ul Li.first-child A,. Pagination ul Li.first-child span {    border-left-width:1px    -webkit-border-bottom-left-rad ius:3px;   &nbsp border-bottom-left-radius:3px;    -WEBKIT-BORDER-TOP-LEFT-RADIUS:3PX;     BORDER-TOP-LEFT-RADIUS:3PX;    -MOZ-BORDER-RADIUS-BOTTOMLEFT:3PX;    -MOZ-BORDER-RADIUS-TOPLEFT:3PX; Pagination ul disabled span,. Pagination ul. Disabled A, pagination ul. Disabled a:hover {color: #999; cursor:defau Lt Background-color:transparent; Pagination ul. Active a,. Pagination ul. Active span {color: #999; cursor:default; pagination ul Li A:hover,. Pagi Nation ul. Active a,. Pagination ul. Active span {background-color: #f0c040; pagination ul Li.last-child A,. paginatio N ul Li.last-child span {   -webkit-border-top-right-radius:3px     border-top-right-radius:3px;    -WEBKIT-BORDER-BOTTOM-RIGHT-RADIUS:3PX;     BORDER-BOTTOM-RIGHT-RADIUS:3PX;    -MOZ-BORDER-RADIUS-TOPRIGHT:3PX;    -MOZ-BORDER-RADIUS-BOTTOMRIGHT:3PX;   Pagination ul li.current A{color: #f00; font-weight:bold; Background: #ddd}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.