Pagination For Search Results

Hello,

I have a search form, which returns a bunch of images. Because their number can be high, I would prefer having the results displayed using pagination. However, I cannot seem to get it to work properly. I have moved everything to the view to keep things as simple as possible.

Here is my code snippet for the search and pagination:




$searchData = $model->search(); // this is the result of the search

$pages = new CPagination($searchData->itemCount); 

$searchData->setPagination($pages); 

$pages->applyLimit($searchData->criteria); 

$pages->pageSize = 2; 



Then, I display the results using a "foreach" statement:




foreach($searchData->getData() as $data)

{

// results displayed here

}



Finally, I have the CLinkPager widget:




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

		'pages' => $pages,

		'header' => 'Отиди на страница: ',

		'nextPageLabel' => 'Следваща',

		'prevPageLabel' => 'Предишна',

			)); 



The problem is: there is not a relation between the widget and the displayed results.

For instance, if I get 4 results, the widget correctly shows that there are 2 pages. However, the results are not displayed in two pages, all are shown in one and clicking the CLinkPager links does nothing.

I have done pagination in the past successfully before, but for all the data using model()->findAll().

How do I state the relation between the pagination widget and the search results… ?

Thank you for your time.