Adding paging on results


I am trying to add pagination on my results page but i am not getting a way to do this, i don’t want to use CGridView or cDetails view etc because my results page is highly customized. Please suggest me a way to use pagination without the need to using grids.

Or it is not possible to achieve in YII?

Please suggest!


Try to use CListView

Follow the advice of R.K, ClistView can be 100% customized.

Take a look to the action index of gii generated crud.

Don’t listen to those guys! :lol:

It’s easy enough:

	public function init() {

    	$criteria = new CDbCriteria;

    	$criteria->select = array('id', 'type', 'author_id', 't.when', 'url', 'project_id', 'subject', 'description', 'DATE(t.when) as theday');

    	$criteria->condition = 'project_id = :project_id';

    	$criteria->together = true;

    	$criteria->params = array('project_id' => $this->projectId);

    	$criteria->order = 't.when DESC';

    	if($this->displayLimit > 0) {

        	$criteria->limit = $this->displayLimit;

    	} else {

        	$this->_pages = new CPagination(ActionLog::model()->find()->count($criteria));

        	$this->_pages->pageSize = 25;



    	$this->_activities = ActionLog::model()->findAll($criteria);


Then in your view:

<?php $activities = $this->getActivities(); ?>

<?php $pages = $this->getPages(); ?>

<?php if(null !== $pages) : ?>

<div class="small" style="float:right;"><?php $this->widget('CLinkPager',array('pages'=>$pages)); ?></div>


<?php endif; ?>

<div id="activity" class="quiet">

	<?php foreach ($activities as $activity): ?>

// do whatever with $activities

	<?php endforeach; ?>


<?php if(null !== $pages) : ?>


<div class="small" style="float:right;"><?php $this->widget('CLinkPager',array('pages'=>$pages)); ?></div>

<?php endif; ?>

Lifted from my own code…

I am not saying that those guys are wrong - they’re not - I’m only saying that you can page without using a listview (or other built-in widget)

But it will probably not be as reusable/flexible when hand-rolling your paging.

if you want every time to update you query’es not only views so you can use @jacmoe posted source code in my opinion better is to use what is written not make everything more complex then it is.

In my case, since it’s already tucked into a widget and only contains four fields, it can’t be beat in performance nor simplicity.

It’s always nice to know that there’s an alternative to the Kosher way. ;)

Thanks for your replies guys, i tried CLinkPager and it works well, however, it creates a new url for each clicked page, whereas my layout requires same urls, so, basically i need ajax based paging.

Please suggest me some resources to achieve this.