Thinkphp Paging method and implementation code

Source: Internet
Author: User
  1. /**
  2. * TODO basic paging in the same code package, making the foreground code less
  3. * @param $m model, reference delivery
  4. * @param $where Query conditions
  5. * @param int $pagesize number of query bars per page
  6. * @return \think\page
  7. */
  8. Function GetPage (& $m, $where, $pagesize =10) {
  9. $m 1=clone $m;//Shallow copy a model
  10. $count = $m->where ($where)->count ();//The JOIN operation will be reset after the operation
  11. $m = $m 1;//to keep the constant, shallow copy a model
  12. $p =new think\page ($count, $pagesize);
  13. $p->lastsuffix=false;
  14. $p->setconfig (' Header ', '
  15. Total %total_row% records per page %list_row% article %now_page% page/Total %total_page% page
  16. ');
  17. $p->setconfig (' prev ', ' prev ');
  18. $p->setconfig (' Next ', ' next page ');
  19. $p->setconfig (' Last ', ' End ');
  20. $p->setconfig (' first ', ' home ');
  21. $p->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end%%header% ');
  22. $p->parameter=i (' Get. ');
  23. $m->limit ($p->firstrow, $p->listrows);
  24. return $p;
  25. }
Copy Code

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

    1. $m =m (' products ');
    2. $p =getpage ($m, $where, 10);
    3. $list = $m->field (True)->where ($where)->order (' id desc ')->select ();
    4. $this->list= $list;
    5. $this->page= $p->show ();
    6. This is the View Code
    7. {$page}
Copy Code

Three, pagination style

  1. . pagination UL {
  2. Display:inline-block;
  3. margin-bottom:0;
  4. margin-left:0;
  5. -webkit-border-radius:3px;
  6. -moz-border-radius:3px;
  7. border-radius:3px;
  8. -webkit-box-shadow:0 1px 2px Rgba (0,0,0,0.05);
  9. -moz-box-shadow:0 1px 2px Rgba (0,0,0,0.05);
  10. box-shadow:0 1px 2px Rgba (0,0,0,0.05);
  11. }
  12. . pagination ul Li {
  13. Display:inline;
  14. }
  15. . pagination UL Li.rows {
  16. line-height:30px;
  17. padding-left:5px;
  18. }
  19. . Pagination ul li.rows B{color: #f00}
  20. . Pagination ul Li A,. Pagination ul Li span {
  21. Float:left;
  22. PADDING:4PX 12px;
  23. line-height:20px;
  24. Text-decoration:none;
  25. Background-color: #fff;
  26. Background:url ('.. /images/bottom_bg.png ') 0px 0px;
  27. border:1px solid #d3dbde;
  28. /*border-left-width:0;*/
  29. margin-left:2px;
  30. Color: #08c;
  31. }
  32. . pagination ul Li a:hover{
  33. color:red;
  34. Background: #0088cc;
  35. }
  36. . Pagination ul Li.first-child a,. Pagination ul Li.first-child span {
  37. border-left-width:1px;
  38. -webkit-border-bottom-left-radius:3px;
  39. border-bottom-left-radius:3px;
  40. -webkit-border-top-left-radius:3px;
  41. border-top-left-radius:3px;
  42. -moz-border-radius-bottomleft:3px;
  43. -moz-border-radius-topleft:3px;
  44. }
  45. . pagination ul. Disabled span,. Pagination ul. Disabled a,. pagination ul. Disabled A:hover {
  46. Color: #999;
  47. Cursor:default;
  48. Background-color:transparent;
  49. }
  50. . Pagination ul. Active a,. Pagination ul. Active span {
  51. Color: #999;
  52. Cursor:default;
  53. }
  54. . pagination ul Li A:hover,. Pagination ul. Active a,. Pagination ul. Active span {
  55. Background-color: #f0c040;
  56. }
  57. . Pagination ul Li.last-child a,. Pagination ul Li.last-child span {
  58. -webkit-border-top-right-radius:3px;
  59. border-top-right-radius:3px;
  60. -webkit-border-bottom-right-radius:3px;
  61. border-bottom-right-radius:3px;
  62. -moz-border-radius-topright:3px;
  63. -moz-border-radius-bottomright:3px;
  64. }
  65. . Pagination ul li.current A{color: #f00; font-weight:bold; background: #ddd}
Copy Code
  • Related Article

    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.