ThinkPHP3.2.3 using pagination

Source: Internet
Author: User

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 &nbsp; <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">&nbsp;{$user. ID}</TD>                    <TDbgcolor= "#FFFFFF">&nbsp;{$user. Account}</TD>                    <TDbgcolor= "#FFFFFF">&nbsp;{$user. pwd}</TD>                </TR>            </foreach>            <TRclass= "Content">                <!--<td colspan= "3" bgcolor= "#FFFFFF" >&nbsp; {$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

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.