使用CActiveDataProvider模型在视图中显示分页

时间:2013-06-28 05:58:57

标签: yii

我有以下代码:

$criteria=new CDbCriteria(array(
    'condition'=>'status='.Post::STATUS_PUBLISHED,
    'order'=>'sortOrder ASC',
    'with'=>'commentCount',               
));                        
$criteria->addSearchCondition('tags','home');
$dataProvider=new CActiveDataProvider('Post', array( 
    'pagination'=>array(   
        'pageSize'=>Yii::app()->params['postsPerPageHome'],
    ),
    'criteria'=>$criteria,
));

$this->render('home',array(
    'dataProvider'=>$dataProvider,    
));

主页查看:

<?php foreach($dataProvider->getData() as $post) { ?>     
            // ....... displaying $post values
       <?php } ?>

如何在上面的视图中显示分页。我搜索过它,我发现只使用zii.widgets.grid.CGridView,但这里我没有使用小部件。

1 个答案:

答案 0 :(得分:3)

您需要CPagination中的CActiveDataProvider

<?php $this->widget('CLinkPager', array(
    'pages' => $dataProvider->pagination,
)); ?>