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 developer, it is necessary to tidy up:
O, first look at the effect chart
First, pagination method
Copy Code code as follows:
/**
* TODO the same code encapsulation for the underlying pagination, making the foreground code less
* @param $m model, reference delivery
* @param $where Query criteria
* @param int $pagesize The number of query bars per page
* @return \think\page
*/
Function GetPage (& $m, $where, $pagesize =10) {
$m 1=clone $m;//Shallow copy a model
$count = $m->where ($where)->count ()//After the join operation will be reset
$m = $m 1;//for the constant operation of the connection, a shallow copy of 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 > Article <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% ');
$p->parameter=i (' Get. ');
$m->limit ($p->firstrow, $p->listrows);
return $p;
}
The GetPage method can be placed in the application/common/common/function.php of the TP framework, which can be dedicated to a number of common methods, where all can be called (such as: Controller file, view file, etc.).
Second, call the paging method
Copy Code code as follows:
$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 ();
The View Code again
<div class= "Pagination" >
{$page}
</div>
Third, the last is the style of pagination, this is a bit messy, because the background frame online download, style has not come and collation, this style can also be achieved, simple.
Copy Code code as follows:
. 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;
Background-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}