Filter goes off when paginated CakePHP (1.3)

Hi CakePHP bakers,

Have you ever came across with a situation where searched filtering goes off (breaks) when you paginated through pages in your web app which was built using CakePHP 1.3 ? Actually, recently, I got an opportunity to deal with a similar problem and it took me a considerable time to judge the root cause behind this problem. I believe, at least there are few people out there who are struggling to get rid from this same situation. So this post is for you people, bakers 🙂

Exact problem :- Assume you have a page, which you are supposed to do a search (Searching users in the db, who have the last name of ‘Silva’). After you perform the search, you will be taken to a page where you will see the filtered results (In this case people who have ‘Silva’ as their last name). (Normally results will be showing below the search criterias, so you will be redirected to the same page with filtered results).  According the SQL limit you have set in your controller, the results will be grouped and showed like in the image below. The problem is when you browse through page 2,3,4 and so on from the pagination links, all your search criterias will go off and results will appear as there was no filter has defined. So in other words you will never be able to access the filtered results except first page. I hope the problem is crystal clear. (Please keep in mind that there is Ajax filtering and pagination available in CakePHP and I am not focussing on that direction)

Continue reading