分页

实现bootstrap的分页样式

  • model代码
public function getAll(){
    $count = $this->count();//总记录数
    $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $show       = $Page->show();// 分页显示输出
    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
    $list = $this->order('myorder desc')->limit($Page->firstRow.','.$Page->listRows)->select();
    $data['page'] = $show;// 赋值数据集
    $data['list'] = $list;// 赋值分页输出
    return $data;
}
  • 控制器代码
// 定义类中常量对象
protected $db;
// 构造函数获得模型对象
public function __construct(){
    parent::__construct();
    // 链接模型
    $this->db = D('Cat');
}
//获取数据
public function index()  
{
    $data=$this->db->getAll();
    $this->data=$data;
    $this->show();
 }
  • css样式

  • html输出

  • 展示如下:


你可能感兴趣的:(分页)