Yii: Default view results to Last Page

I have pages of result and want to default the view to last page, and found the solution here.

In controller action function:

public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('model',array(
        'pagination'=>array(
            'pageSize'=>10,
        )
    ));
    $pager=$dataProvider->pagination;
    $pager->itemCount=$dataProvider->totalItemCount;
    if(!Yii::app()->request->isAjaxRequest)
        $pager->currentPage=$pager->pageCount;
 
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

Note: line 11.

Leave a Reply

Your email address will not be published. Required fields are marked *