Use CPagination with createCommand function


I am trying to use CPagination.The example shown here is using criteria. I am using stored procedure for selecting the data. The database used is postgresql. I am calling the stored procedure using create command function.

$command = Yii::app()->db->createCommand("select sp_images_select(:project_id,:milestone_id);");




How can I use CPagination with the result set of this command. I am using ajax to display the image gallery as explained here

Please help.

Thanks in advance.

you can use CArrayDataProvider

$rawData=Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll();

// or using: $rawData=User::model()->findAll();

$dataProvider=new CArrayDataProvider($rawData, array(




             'id', 'username', 'email',







Thanks for the reply. I am not using CGridview. I am just using a for loop for the result set. How can I use CArrayDataProvider with CLink pager?

I was able to do the pagination by using CSqlDataProvider. First I created the dataprovider using

function search()


$command =Yii::app()->db->createCommand("SELECT COUNT(*) FROM sp_images_select()");



$sql="SELECT * FROM sp_images_select()";


$dataProvider=new CSqlDataProvider($sql, array(








    return $dataProvider;


Then in controller



            $list =$dataprovider->data;


In view I used CLinkPager

$this->widget(‘CLinkPager’, array(‘pages’ => $pages));

Now the problem is I am using renderPartial() to display the contents of this view using ajax inside another view. But when I click on the pagination links it is going to the action. Ajax is not working.