Search + Pagination + Post request

I’m currently working on a data management system and have run into a bit of a problem.

I have a search feature which allows you to filter any of the record fields and the results are displayed in a grid which is split up into pages. In order for filter criteria to be applied when you move onto another page I was submitting the search criteria via GET which worked fine, unfortunately I had to add several new fields for the client and now I get a 414 Request URI too long error.

Two solutions seem obvious:

  • Submit the search criteria via POST, but I need some way for these values to be carried between search result pages. Perhaps I could serialize the criteria into a session and pass the session ID via a GET variable?

  • I could only include variables in the URL if they are not empty (ie. only the criteria which are not blank are included) as it is unlikely all the criteria would be applied at once. I’m not sure how to achieve this though.

Any help would be appreciated.

Cheers, Tim.

imho sessions are started automatically bu yii. you can just save array to session and use it in another controller or action

The problem is that I’d like for the criteria to be empty when you open the page, rather than having it remember your earlier criteria. The way I was thinking if there was a session ID in the URL it would load the criteria from that session, if not the criteria would be empty.

Okay, I think I worked something out.

Basically I generate a unique ID which is passed as a GET variable when the search form is submitted, for example /customers?sid=4f43a9ea3a19c

I then save a copy of this sid in my session, along with a serialized copy of the search parameters.

When the page is loaded without the criteria POST variable being set it first checks to see if there is a sid GET variable, if there is and it matches the value stored in the session then it uses the serialized criteria. If the sid is not set (say a cold page open), or the sid does not match (say they refreshed a tab from an older search) then the criteria is cleared.

Any suggestions for my method are welcome :)