TP3.2 Framework Manual, there is a data paging, but each time to write too much code, there are Chinese settings and other problems, as a program developer, it is necessary to tidy up:
O, look first
One, pagination method
/** * TODO the same code package for basic paging, making the foreground code less * @param $m model, reference passing * @param $where query criteria * @param int $pagesize Query number per page * @return \think\pa GE */function getpage (& $m, $where, $pagesize =10) { $m 1=clone $m;//Shallow copy a model $count = $m->where ($where)- >count ();//The JOIN operation will be reset after the operation $m = $m 1;//To maintain the constant habitual operation, shallow copy a 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> Section <b>%NOW_PAGE%</b> page/Total <b>%TOTAL_PAGE%</b> page </li> '); $p->setconfig (' prev ', ' prev '); $p->setconfig (' Next ', ' next page '); $p->setconfig (' Last ', ' End '); $p->setconfig (' first ', ' home '); $p->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end%%header% '); $p->parameter=i (' Get. '); $m->limit ($p->firstrow, $p->listrows); return $p;}
The GetPage method can be placed in the TP framework of the application/common/common/function.php, this document can be specifically placed in a number of common methods, where can be called (such as: Controller files, view files, etc.).
Second, call the paging method
$m =m (' products '); $p =getpage ($m, $where); $list = $m->field (True)->where ($where)->order (' id desc ') Select (); $this->list= $list; $this->page= $p->show ();
Then the view Code.
<div class= "pagination" > {$page}</div>
Third, the end is the style of pagination, this is a bit messy, because the background frame download, style has not come and finishing, this style can also be implemented by themselves, simple.
. pagination ul {display:inline-block; margin-bottom:0; margin-left: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; padding-left:5px;}. Pagination ul li.rows B{color: #f00}.pagination ul Li A,. Pagination ul Li span {float:left; 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-radius:3px; 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:default;ba Ckground-color:transparent;}. Pagination ul. Active a,. Pagination ul. Active span {color: #999; cursor:default;}. Pagination ul Li A:hover,. Pagination ul. Active a,. Pagination ul. Active span {background-color: #f0c040;}. Pagination ul Li.last-child a,. Pagination 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}
Category: PHP
ThinkPHP3.2 Paging Implementation