新建一个分页控制器
PageController.class.php
代码如下
<?php
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller{
public function index(){
// 获取当前页码,默认第一页,设置每页默认显示条数
$nowpage = I('get.page', 1, 'intval');
$limits = 8;
// 获取总条数
$count = M('Address') -> count();
// 计算总页面
$allpage = ceil($count / $limits);
$allpage = intval($allpage);
$lists = M('Address')
-> page($nowpage, $limits) // page 方法分页
-> order('id asc')
-> select();
// 跳转分页输出
/* $this -> assign('lists', $lists);
$this -> assign('allpage', $allpage);
$this -> assign('nowpage', $nowpage);
$this->display();*/
// ajax 分页输出
$info = array('lists'=>$lists,'allpage'=>$allpage,'nowpage'=>$nowpage);
$this->ajaxReturn($info,'json');
}
public function test(){
$this->display('index');
}
}
page/index.html页面代码
layPage demo{ : : } { : } { : : : : : : } { } {$vo.id}:{$vo.name}(curr){ .({ : curr }(res){ view = .()li = list = res..(list(indexarray){ li += +array.+})view.= li({ : : res.allpage: res.nowpage: : : (objfirst){ (!first){ (obj.)} } })})}()