时间:2021-07-01 10:21:17 帮助过:14人阅读

1、在公共函数Application/Common/Common/function.php中书写:
function getpage($count,$pagesize=10) {
$page=new Think\Page($count,$pagesize);
$page->setConfig('header', '在控制器PageController.class.php中调用
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller {
public function index() {
$m=M('user');
$count=$m->count();
$page= getpage($count,8);//Common/function.php中分页
$list=$m->limit($page->firstRow,$page->listRows)->select();
$this->assign('list',$list);//赋值数据集
$this->assign('page',$page->show());//赋值分页输出
$this->display();
}
}
在视图index/index.html中显示
用户名: {$vo['name']}
| {$page} |
样式的书写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:#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;
}
2、在模板UserModel.class.php中书写分页函数
namespace Home\Model;
use Think\Model;
class UserModel extends Model {
public function getPage() {
$page=I('p',0,'int');
$limit=8;
$data=$this->page($page,$limit)->select();
$count= $this->count();
$Page=new \Think\Page($count, $limit);
$Page->lastSuffix=false;//是否显示总页数
$Page->setConfig('header','控制器PageController.class.php中调用
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller {
public function index() {
$m=D('Upload_img');
$list=$m->getPage();//model中分页
$this->assign('list',$list);//赋值数据集
$this->display();
}
}
视图显示index/index.html
用户名: {$vo['name']}
| {$list.page} |
分页的样式与第1中公共方法中page.css中样式相同
以上引用文件常量"__CSS__"在公共配置文件中配置:
return array( 'TMPL_PARSE_STRING'=>array( '__CSS__'=>__ROOT__.'/Public/Css', ))
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。