Skip to content Skip to sidebar Skip to footer

Pagination For A Table Contents In Yii

I'm using Yii application. In that how to give pagination to a table contents (not using cgridview). In view, =>array( // this is used in contact page'adminEmail'=>'webmaster@example.com', 'listPerPage'=> 10,//default pagination size ),

Now, modify your controller's action like:

publicfunctionactionOutbox() {
        $criteria = new CDbCriteria;
        $criteria->condition = 'from_userid = :id';
        $criteria->order = 'time DESC';
        $criteria->params = array (':id'=>Yii::app()->user->id);

        $item_count = Email::model()->count($criteria);
        $model      = Email::model()->findAll($criteria);

        $pages = new CPagination($item_count);
        $pages->setPageSize(Yii::app()->params['listPerPage']);
        $pages->applyLimit($criteria);

        $this->render('outbox', array(
            'model' => $model,
            'item_count'=>$item_count,
            'page_size'=>Yii::app()->params['listPerPage'],
            'items_count'=>$item_count,
            'pages'=>$pages,
        ));
    }

Then in your view after foreach loop add CLinkPager widget, like:

<?php$this->widget('CLinkPager', array(
            'currentPage' => $pages->getCurrentPage(),
            'itemCount' => $item_count,
            'pageSize'=> $page_size,
            'maxButtonCount' => 5,
            //'nextPageLabel' =>'My text >','htmlOptions' => array('class'=>'pages'),
        ));
?>

Thats all you need to do, you might have to do some css changes though, hope that helps :)

Post a Comment for "Pagination For A Table Contents In Yii"

Element?

I have a table and I need the cells to have an element posi…