本文实例讲述了Yii实现简单分页的方法。分享给大家供大家参考,具体如下:
yii分页方法
function actionPage(){ $criteria=new CDbCriteria(); $count=Archives::model()->count($criteria); $pages=new CPagination($count); // results per page $pages->pageSize=10; $pages->applyLimit($criteria); $models=Archives::model()->findAll($criteria); $this->render('Archives', array( 'models' => $models, 'pages' => $pages ));}
view视图的方法
<ul><?php foreach($models as $model): ?> <li><?php echo $model->title;?></li><?php endforeach; ?></ul><?php $this->widget('CLinkPager', array( 'pages' => $pages, 'header'=>'', 'prevPageLabel'=>'上一页', 'nextPageLabel'=>'下一页', 'cssFile'=>'css/cc/css.css',)) ?>