Pagination class and Search Function help! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Pagination class and Search Function help! (/showthread.php?tid=9727) |
Pagination class and Search Function help! - El Forum - 07-06-2008 [eluser]Devon Lambert[/eluser] I've been at this one for a few hours now and thought it couldn't hurt to hit up the CI community for some much needed Ninja Style assistance. Here's the deal: I've created a quick and dirty CI search function and have made use of it in my controller and view. I've whipped up a table with a little bit of css styling that is calling in my search results. I do not want to break this setup and I do not want to shift any view code into my controller or model, besides, that wouldn't be the right MVC thing to do would it? The main issue is that when I click on my 2nd paginated link, I receive the following error: Code: Severity: Warning Here is the code I have so far: CONTROLLER: Code: <?php MODEL: Code: <?php VIEW: Code: <div class="search-container"> So far, I can get the search function to work just fine, but when I combine this with the pagination and go to any other page besides the first search page, it's as if the post data I went searching for gets thrown out. Please, any help is definitely appreciated in getting this working. :-) Pagination class and Search Function help! - El Forum - 07-06-2008 [eluser]Michael Wales[/eluser] Quote:it’s as if the post data I went searching for gets thrown out.It does. When a user searches, they are sending a post request to the controller. Now, when they click the pagination link, a whole new request is being sent to that controller's method. There's no $_POST array and nothing there to tell your search function what to search for. A few options: 1) My favorite: include the search term as a segment within the URI. 2) Use a Javascript library to unobtrusively stop the default action on the pagination links and rather, submit a hidden form with the original search term and the offset segment from the pagination link). 3) Probably the easiest: Set a session variable to hold the search term and use it if there is no term within the $_POST array. Pagination class and Search Function help! - El Forum - 07-06-2008 [eluser]Devon Lambert[/eluser] Michael Wales you are my hero! :-) Pagination class and Search Function help! - El Forum - 08-18-2008 [eluser]Cambo[/eluser] [quote author="Michael Wales" date="1215423721"] Quote:it’s as if the post data I went searching for gets thrown out.It does. When a user searches, they are sending a post request to the controller. Now, when they click the pagination link, a whole new request is being sent to that controller's method. There's no $_POST array and nothing there to tell your search function what to search for. A few options: 1) My favorite: include the search term as a segment within the URI. 2) Use a Javascript library to unobtrusively stop the default action on the pagination links and rather, submit a hidden form with the original search term and the offset segment from the pagination link). 3) Probably the easiest: Set a session variable to hold the search term and use it if there is no term within the $_POST array.[/quote] Hi Michael I am trying pagination by passing uri segments to the controller, rather than post data. I am having the same issue so obviously I have to recreate the uri but I am not sure where. Can you give an example for your No 1 option. Thanks Cambo Pagination class and Search Function help! - El Forum - 08-19-2008 [eluser]Cambo[/eluser] Hi Michael Relax, I solved it. :coolsmile: (after a couple hours of r&d Here's what I ended up with. Hope it helps some-one out. Regards Cambo Code: $total_rows = count($this->objCars->searchCars($marque,$model,$state,$retail,$body,$sortby)); |