Thinkphp3.2.3 paging usage example analysis_php example

WBOY
Release: 2016-08-17 13:02:38
Original
952 people have browsed it

The first thing to understand is that the paging class of ThinkPHP3.2.3 has been moved to ThinkPage.class.php. This is somewhat different from the previous version. It is still similar to the previous version in use, but the default effect cannot be complimented. So it's best to add some styles yourself.

I added some styles (not very pretty), you can improve the paging style by yourself, the effect picture:

Here I first made the page settings into a function getpage, and put this method in ApplicationCommonCommonfunction.php (note that function is not a class) to facilitate calling from other places. The code is as follows:

<&#63;php
/**
 * TODO 基础分页的相同代码封装,使前台的代码更少
 * @param $count 要分页的总记录数
 * @param int $pagesize 每页查询条数
 * @return \Think\Page
 */
function getpage($count, $pagesize = 10) {
  $p = new Think\Page($count, $pagesize);
  $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
  $p->setConfig('prev', '上一页');
  $p->setConfig('next', '下一页');
  $p->setConfig('last', '末页');
  $p->setConfig('first', '首页');
  $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
  $p->lastSuffix = false;//最后一页不显示为总页数
  return $p;
}
&#63;> 
Copy after login

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); // 赋值数据集
    $this->assign('page', $p->show()); // 赋值分页输出
    $this->display();
  } 

Copy after login

Next usage in View:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户信息输出</title>
    <link href="__ROOT__/Public/Css/style.css" rel="stylesheet" type="text/css" />
    <link href="__ROOT__/Public/Css/mypage.css" rel="stylesheet" type="text/css"/>
  </head>

  <body>
    <table width="405" border="1" cellpadding="1" cellspacing="1" bgcolor="#99CC33" bordercolor="#FFFFFF">
      <tr>
        <td colspan="3" bgcolor="#FFFFFF" class="title" align="center">当前登录用户:{$Think.session.admin}</td>
      </tr>
      <tr>
        <td colspan="3" bgcolor="#FFFFFF" class="title" align="center">用户信息</td>
      </tr>
      <tr class="title">
        <td bgcolor="#FFFFFF" width="44">ID</td>
        <td bgcolor="#FFFFFF" width="120">用户名</td>
        <td bgcolor="#FFFFFF" width="223">密码</td>
      </tr>
      <foreach name='select' item='user' >
        <tr class="content">
          <td bgcolor="#FFFFFF"> {$user.id}</td>
          <td bgcolor="#FFFFFF"> {$user.account}</td>
          <td bgcolor="#FFFFFF"> {$user.pwd}</td>
        </tr>
      </foreach>
      <tr class="content">
        <!--<td colspan="3" bgcolor="#FFFFFF"> {$page}</td>-->
        <td colspan="3" bgcolor="#FFFFFF"><div class="pages">
            {$page}
        </div></td> 
      </tr>
    </table>
  </body>
</html> 

Copy after login

The paging style mypage.css is set 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;
} 

Copy after login

That’s it.

The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support Script Home.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template