phpcakephp

Cakephp pagination issue


I am facing an issue with the pagination helper. I am sorting the records based on user criteria like date range etc via drop downs:

alt text

And it paginates properly. But when I click on page 2, it shows page 2 of all results and not the sorted results. How can I fix it? The fields are sorted via POST and not GET and don't want it to be GET.


Solution

  • You can try to store the post in the session, and then to fetch it when the page is loaded.

    i.e.

    if(isset($this->data)){
       if(isset($this->data['clear'])){ //some field (button) which will clear the session
           $this->Session->delete('post');
           unset($this->data);
       }
       $this->Session->write('post', $this->data);
    }
    
    if($this->Session->read('post')){
       $this->data = $this->Session->read('post');
    }
    

    If you want take a look on this component: Filter component. The post is a little bit old, but the component is adequate still and I am using it in my projects :)