In previous lesson, i talked about pagination in cakephp 1.1. In this lesson, i’m going to talk about pagination search result in cakephp 1.1.(like previous method).
With PaginationHelper and PaginationComponent in previous lesson, they only help conventional pagination. But, when we add search condition into request, pagination has been error. The reason is that when we implement paging of pages the variables will be transmitted via a URL in the GET method. So that the filter conditions in the form will not be passed on, and when intializing the page, it will not understand the conditions transmitted from the GET method, so paging no longer accurate.
- Transmit all conditiona and parameters via a URL in the GET method
- Transmit filter condition to the POST method and pagination parameter to the URL in the GET method.
return $this->Html->link($title,$url,NULL,NULL,$escapeTitle)
to :
$options['onclick'] = "return paginator_number('form', '{$this->Html->url($url)}')";
return $this->Html->link($title,$url,$option,NULL,$escapeTitle)
Above, we called ‘pagination_number’ function with 2 parameters:
- Name of form : ‘form’
- Url with paging parameters (this value will be auto generate, we needn’t change)
Note : You must set name to form is ‘form’, otherwise, function can’t run.
After that, we will add function :
function paginator_number(element, url ) {
$(element).attr("action",url);
$(element).submit();
return false;
}
This function will be add to layout. It use some function of jquery. If you don’t import JQuery, import it now. Good luck.