I have a controller function that displays all records, I am using the pagination class to divide the records in pages. The controller looks a bit like that
class Example extends CI_Controller {
[...]
function All()
{
//Gets all the records
//Pagination uri_segment set to 3
}
}
Now i added the ability to search the records. I need the search term to be in the uri so the function is like function All($search_term = false). My issue is that the function may or may not have search terms. and depending on that, the uri segment of the pagination will change. without a search term uri_segment is 3, with it is 4.
Is there a way to fix that while using the same function and having the search term in the url?
It can be done various ways, personally I would do something simple like store it in session or cookie, but you can do URI as well refer to the CI forum for this one:
http://codeigniter.com/forums/viewthread/59364/
Keep in mind that people may type non URI friendly strings into your search term and you will have to urlencode / decode the values in order to put them in a string, something you don’t need with cookies, or sessions. But again I see the benefit for copy & pasting the link to someone for search results.