Pagination in yii is quite simple. Before you can understand the solution i am presenting below you need to know how YII works basically and the model controller and view approach of yii:
Add following code in your controller action function:
function actionIndex(){
$criteria = new CDbCriteria();
$count=Article::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models = Post::model()->findAll($criteria);
$this->render('index', array(
'models' => $models,
'pages' => $pages
));
}
And to display the pagination in view file simply use following code:
<?php foreach($models as $model): ?>
// display a model
<?php endforeach; ?>
// display pagination
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?>
This is just a copy/paste from Yii documentation:
http://www.yiiframework.com/doc/api/1.1/CPagination
what is the new in it. You have copied the content and pasted here.
i don't know it is pasted content, but it helps beginners like me. It helped me. because it is simple.
Keep it up.
I used this code, pagination came .. but how can i change my select query depend up on pagination count