ThinkPHP3.2.3 implementation of pagination method _php instance

Source: Internet
Author: User
In this paper, we describe the method of ThinkPHP3.2.3 implementing paging. Share to everyone for your reference, as follows:

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 nice), you can improve the page style by yourself:

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 the same code package for basic paging, so that the foreground code is less * @param $count the total number of records to be paged * @param int $pagesize number of query bars per page * @return \think\page */fun Ction getpage ($count, $pagesize = ten) {  $p = new Think\page ($count, $pagesize);  $p->setconfig (' Header ', '
  • Total %total_row% records %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->lastsuffix = false;//The last page does not appear as the total number of pages return $p;}? >

    The code used in the controller is as follows:

    Public Function Showallusers () {    $m = m (' User ');    $where = "id>10";    $count = $m->where ($where)->count ();    $p = GetPage ($count, 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:

          
     
      
         <title>User Information output</title>    
     
      
         
     
      
             
     
              
    
      
     
      
      
     
         {$page} --> 
        
    currently logged on User: {$Think. session.admin}
    user information
    id username password
    {$user. account} {$user. pwd}

    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:700;  Border-color: #50A8E6;}

    That's all you can do.

    More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Method Summary", "PHP Cookie Usage Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."

    It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

  • 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.