自定义的tp3.23分页

分四个步骤
1,控制器
$this->m 是模型

$count = t h i s − > m − > w h e r e ( this->m->where( this>m>where(map)->count();
p = g e t p a g e ( p = getpage( p=getpage(count,10);
$data = t h i s − > m − > w h e r e ( this->m->where( this>m>where(map)->order(‘sort desc, id asc’)->limit($p->firstRow, $p->listRows)->select();
$this->assign(‘data’, $data);// 赋值数据集
$this->assign(‘count’, $count);
$this->assign(‘page’, $p->show()); // 赋值分页输出,

2,Common公共模块的公共方法function.php写分页样式

<?php /** * TODO 基础分页的相同代码封装,使前台的代码更少 * @param $count 要分页的总记录数 * @param int $pagesize 每页查询条数 * @return \Think\Page */ function getpage($count, $pagesize = 10) { $p = new Think\Page($count, $pagesize); $p->setConfig('header', '
  • %TOTAL_ROW%条记录 每页' . $pagesize . '条 第%NOW_PAGE%页/共%TOTAL_PAGE%
  • '); $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; } **3,导入public静态资源文件到模板中** 其中分页样式page.css如下 ``` .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:#429842; } .pages a.first,.pages a.prev,.pages a.next,.pages a.end{ margin:0; } .pages a:hover{ border-color:#429842; color: #ffffff; /*font-weight: bold;*/ background:#429842; } .pages span.current{ background:#429842; color:#FFF; font-weight:700; border-color:#429842; } ``` **4,模板中显示分页**
    {$page}
    最终效果图![在这里插入图片描述](https://img-blog.csdnimg.cn/20190721170648174.png)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值