Using AjaxHelper for pagination in CakePHP 1.3

I am using CakePHP since last 5 years, and am quite used to of “AjaxHelper” for developing Ajax features using CakePHP. But from version 1.3 CakePHP has started deprecating the “AjaxHelper” replacing it with new “JsHelper”, which can be used with many JS libraries.

While AjaxHelper is still there for people like me. There is at least one big change that I noticed just now. It is related with working of Ajax Pagination.

Now the “Paginator” helper by default uses “JsHelper”, for generating the Javascript links. Now if you are trying to avoid using JQuery then you need some way to tell the “Paginator” helper to use “AjaxHelper” instead of JsHelper. Although the CakePHP documentation mentions that you can set the default helper value to Ajax Helper using following code, but it does not worked for me.

$this->set('posts', $this->paginate());
//Add this line below above line
$this->helpers['Paginator'] = array('ajax' => 'Ajax');

I tried it several times changing values and variables but no success.

Instead of above you can use following two lines in the view file to tell the “Paginator”, to use Ajax helper.

$this->Paginator->_ajaxHelperClass = "Ajax";
$this->Paginator->Ajax = $this->Ajax;
$this->Paginator->options(array("update" => "",'evalScripts' => true));

You also do NOT need to add the line

echo $this->Js->writeBuffer();

at the end of view file.

Scroll to top