Pagination Not Working With Querybuilder

Hi i am trying to use pagination with query builder but it is not working.

Here is my Controller code

$category_prods = Product::model()->getCategoryProducts($categoryid, $categoryname);

$totalrecords = count($category_prods);

$criteria = new CDbCriteria;


$pages = new CPagination($totalrecords);

$pages->pageSize = 8;



$data['products_data'] = $category_prods;


//passing data to view

$this->render('index', array(

	'data' => $data,

	//'posts' => $posts,

	'pages' => $pages


HERE IS my View Code

foreach($data['products_data'] as $product): 

	echo "Title:".$product['title']."<br>Product ID:".$product['id']."<br><br>";




$this->widget('CLinkPager', array(

	'pages' => $pages,

)) ;

The out is: all records are displaying simultaneously And the pager is also displaying. please help me. i dont know what wrong with it.

I’m not sure CLinkPager works alone in a view without being part of a widget like CListView or CGridView. Could that be the problem?

the same code works perfectly if i get data via Active record. when i use query builder to fetch data, then it is not working. i am unable to understand. is there anyone who can guide me.