YII 1.0 分页类
在控制器中
方法1
$criteria = new CDbCriteria();//AR的另一种写法 $model = Article::model(); $total = $model->count();//统计总条数 $pager = new CPagination($total);//实例化分页类 $pager->pageSize = 4;//每页显示多少条 $pager->applyLimit($criteria);//进行limit截取 $info = $model->findAll();//查询截取过的数据 $data = array("articleInfo"=>$info,"pages"=>$pager); $this->render("index",$data);
方法二
$model = Article::model(); $total = $model->count();//统计总条数 $pager = new CPagination($total);//实例化分页类 $pager->pageSize = 4;//每页显示多少条 $page = max(intval(@$_GET['page']),1); $limit = (($page-1)*4).',4'; $info = $model->findAllBySql("select * from {{article}} order by id desc limit $limit");//查询截取过的数据 $data = array("articleInfo"=>$info,"pages"=>$pager); $this->render("index",$data);
模板中
<div class="page"> <?php $this->widget('CLinkPager', array( 'header' => '', 'firstPageLabel' => '首页', 'lastPageLabel' => '末页', 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页', 'pages' => $pages, 'maxButtonCount'=> 5, )); ?> </div>