AJAX and ClinkPager

I have a search form where I’m using AJAX to display the results. In the results I’ve extended the CLinkPager class so that I can use an ajaxLink() on the paging so that only the results div is refreshed.

The issue I’m running into is that when you go to click on the next page of results it ends up returning all results instead of going to the next page of results from the search. It doesn’t seem to hold the search term that was originally searched for. I think it’s because in the method I have inside the controller is looking for a $_POST but the pager doesn’t continue to POST the form.

My new Pager looks like this:




<?php

class AjaxPager extends CLinkPager

{


     protected function createPageButton($label,$page,$class,$hidden,$selected)

     {

		if($hidden || $selected)

			$class.=' '.($hidden ? self::CSS_HIDDEN_PAGE : self::CSS_SELECTED_PAGE);

		return '<li class="'.$class.'">'.CHtml::ajaxLink($label,$this->createPageUrl($page),array('update'=>'#searchResults')).'</li>';

	}

}

?>




I can include the controller code as well if needed.

Thanks,

Ben

It’s easy to change to type=post. I guess you’ll have to add ‘data’ too.




CHtml::ajaxLink(

  $label,

  $this->createPageUrl($page),

  array('update'=>'#searchResults', 'type'=>'POST','data'=>array('page'=>$page+1, 'ajax'=>1))

)



In the controller




$pages->setCurrentPage($_POST['page']-1); //stored in $_GET['page']



(page is zero indexed, +1/-1 could be left out)

/Tommy

Thanks. That worked perfectly.