The first thing to make clear is that the ThinkPHP3.2.3 page class has been moved to the think\page.class.php, which is different from the previous version, the use of or similar to the previous version, but the default effect is not flattering, so it is best to add some of their own style.
I added some style (not very good), we can go on their own to improve,:
Here I have the page set to make a function getpage, put this method to application\common\common\function.php (note function is not a class) convenient for other places to call, the code is as follows:
<?PHP/** * TODO basic pagination in the same code package, make the foreground code less * @param $m model * @param $where query criteria * @param int $pagesize Query number per page * @return \think\page */functionGetPage ($m,$where,$pagesize= 10) { $count=$m->where ($where),Count(); $p=NewThink\page ($count,$pagesize); $p->setconfig (' header ', ' <li class= ' rows ' > Total <b>%TOTAL_ROW%</b> records <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% '); return $p;}?>
The code used in the controller is as follows:
Public functionshowallusers () {$m= M (' User '); $where= "Id>10"; $p= GetPage ($m,$where, 1); $list=$m->field (true)->where ($where)->order (' id ')->limit ($p->firstrow,$p->listrows)Select (); $this->assign (' select ',$list);//Assignment Data Set $this->assign (' page ',$p->show ());//Assignment Paging output $this-display (); }
Next use in view:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <title>User Information output</title> <Linkhref= "__root__/public/css/style.css"rel= "stylesheet"type= "Text/css" /> <Linkhref= "__root__/public/css/mypage.css"rel= "stylesheet"type= "Text/css"/> </Head> <Body> <Tablewidth= "405"Border= "1"cellpadding= "1"cellspacing= "1"bgcolor= "#99CC33"bordercolor= "#FFFFFF"> <TR> <TDcolspan= "3"bgcolor= "#FFFFFF"class= "title"Align= "Center">Currently logged on User: {$Think. session.admin}</TD> </TR> <TR> <TDcolspan= "3"bgcolor= "#FFFFFF"class= "title"Align= "Center">User Information</TD> </TR> <TRclass= "title"> <TDbgcolor= "#FFFFFF"width= "$">Id</TD> <TDbgcolor= "#FFFFFF"width= "+">User name</TD> <TDbgcolor= "#FFFFFF"width= "223">Password</TD> </TR> <foreachname= ' SELECT 'Item= ' user '> <TRclass= "Content"> <TDbgcolor= "#FFFFFF"> {$user. ID}</TD> <TDbgcolor= "#FFFFFF"> {$user. Account}</TD> <TDbgcolor= "#FFFFFF"> {$user. pwd}</TD> </TR> </foreach> <TRclass= "Content"> <!--<td colspan= "3" bgcolor= "#FFFFFF" > {$page}</td> - <TDcolspan= "3"bgcolor= "#FFFFFF"><Divclass= "pages">{$page}</Div></TD> </TR> </Table> </Body></HTML>
Where to set the style of pagination mypage.css, as follows:
. Pages A,.pages span{Display:Inline-block;padding:2px 5px;margin:0 1px;Border:1px solid #f0f0f0;-webkit-border-radius:3px;-moz-border-radius:3px;Border-radius:3px;}. Pages A,.pages Li{Display:Inline-block;List-style:None;text-decoration:None;Color:#58A0D3;}. Pages a.first,.pages a.prev,.pages a.next,.pages a.end{margin:0;}. Pages A:hover{Border-color:#50A8E6;}. Pages Span.current{background:#50A8E6;Color:#FFF;Font-weight: the;Border-color:#50A8E6;}
That's all you can do.
ThinkPHP3.2.3 using pagination