Yii 中使用分页
更新:HHH   时间:2023-1-7


  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

返回web开发教程...