首页 > 其他 > 详细

Yii 中使用分页

时间:2015-10-26 13:52:28      阅读:192      评论:0      收藏:0      [点我收藏+]
  1. Controller中的代码:

public function actionIndex(){

    $categoryModel = Category::model();

    $criteria = new CDbCriteria();

    $criteria->order = ‘id ASC‘;

    $criteria->addCondition(‘status=1‘);      //根据条件查询

    $count = Category::model()->count($criteria);

    $pager = new CPagination($count);

    $pager->pageSize=2;

    $pager->applyLimit($criteria);

    $categoryInfo = Category::model()->findAll($criteria);

    $this->render(‘index‘,array(‘pages‘=>$pager,‘categoryInfo‘=>$categoryInfo));

}


2. view视图中的调用:

<?php $this->widget(‘CLinkPager‘,array(

    ‘header‘ => ‘‘,

    ‘firstPageLabel‘ => ‘首页‘,

    ‘lastPageLabel‘ => ‘最后一页‘,

    ‘prevPageLabel‘ => ‘上一页‘,

    ‘nextPageLabel‘ => ‘下一页‘,

    ‘pages‘ => $pages,

    ‘maxButtonCount‘=>3,

));?>


参考: http://www.yiichina.com/code

Yii 中使用分页

原文:http://itsart.blog.51cto.com/1005243/1706252

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!