thinkphp paging Implementation, thinkphp paging implementation
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 basic pagination in the same code package, make foreground code less * @param $m model, reference Pass * @param $where query criteria * @param int $pagesize Query number per page * @return \think\ Page*/functionGetPage (&$m,$where,$pagesize=10){ $m 1=Clone $m;//Shallow copy a model $count=$m->where ($where),Count();//operations such as join are reset after a habitual operation $m=$m 1;//to maintain a constant, shallow copy of a model $p=NewThink\page ($count,$pagesize); $p->lastsuffix=false; $p->setconfig (' Header ', '
Total %total_row% records per page %list_row% article %now_page% page/Total %total_page% page'); $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, ten); $list=$m->field (true)->where ($where)->order (' id desc ') Select (); $thislist=$list; $this->page=$p->show ();
Then the view Code.
{$page}
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;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}
thinkphp How to realize paging and mail sending
The paging of TP is actually very simple:
First you need to import the paging class.
The code is as follows:
$User = M (' User '); Instantiating a User object
Import (' ORG. Util.page ');//Import page-out class
$count = $User->where (' Status=1 ')->count ();//query satisfies the required total number of records
$Page = new Page ($count, 25);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page
$show = $Page->show ();//pagination display output
Querying for paging data note the parameters of the limit method to use the properties of the page class
$list = $User->where (' Status=1 ')->order (' Create_time ')->limit ($Page->firstrow. ', '. $Page->listrows )->select ();
$this->assign (' list ', $list);//Assignment Data set
$this->assign (' page ', $show);//Assignment Paging output
$this->display (); Output template
thinkphp Data Paging (article pagination)
Article paging, I remember there should be a thinkphpcms you look for that installation again to see how that wrote. You can do that--
http://www.bkjia.com/PHPjc/893202.html www.bkjia.com true http://www.bkjia.com/PHPjc/893202.html techarticle thinkphp Paging Implementation, thinkphp page Implementation 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 development ...