![]() |
Pagination/Validation: What to do? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Pagination/Validation: What to do? (/showthread.php?tid=29956) |
Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]carvingCode[/eluser] Interesting code structure problem I need help with. I implemented form validation using a if/else block. Checking to see if form was validated -- if not, open form; otherwise, continue on into function. All worked wonderfully until I added pagination code, which BTW seems to work fine in tests after removing validation if/then statement. But, with validation code in, clicking on the pagination links bring me back into the function and validation fails and the form opens. I'm calling the form from a controller function. It sends it's data to the function I'm having problems with. Code is below. Output is sent to a view with a loop. I've run up against a wall in trying to determine proper program flow and would appreciate any thoughts. If you need additional info, please ask. TIA Code: // In controller Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]pickupman[/eluser] In order to have pagination work on a search term you'll have to do one of two things. 1. Store search term in a user's session 2. Store the search to the DB and access via query id (like done here on the forums) To solve your problem, I would suggest once you have passed form validation redirect the user to a url with search results being pulled from one of the methods mentioned above. In the search results method check if search term is set in 1 or 2, and if not redirect back to the search page. Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]carvingCode[/eluser] [quote author="pickupman" date="1272408838"]To solve your problem, I would suggest once you have passed form validation redirect the user to a url with search results being pulled from one of the methods mentioned above. In the search results method check if search term is set in 1 or 2, and if not redirect back to the search page.[/quote] In other works, I can have one controller that acts as a gatekeeper (handles validation and routing) and another controller, a 'display controller', which contains pagination and calls to search methods (in models) Then, my pagination URLs point back to the method in the 'display' controller. Am I understanding correctly? Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]pickupman[/eluser] No need for the separate controller something like: Code: //One Controller Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]carvingCode[/eluser] Got it. Thanks for the help! I made the modifications you suggested and everything works great. Validation and pagination -> beautiful. I am wondering though if there might be another option other than using 'redirect'? It works fine, but visually, there's a redrawing of the page that occurs and a slight slowdown in the page being drawn. Short of an Ajaxian solution, any ideas? TIA Pagination/Validation: What to do? - El Forum - 04-27-2010 [eluser]pickupman[/eluser] Just not use validation. If a user passes an empty form, display a "No results found page". Or just do a plain redirect without the 'location' parameter might speed it up. That just makes it work when some hits reload on the search page, and it doesn't re-prompt to submit the page again. Pagination/Validation: What to do? - El Forum - 04-28-2010 [eluser]carvingCode[/eluser] Wondering: Is there any MVC violation in putting pagination code and calls to a model method in a view? Here's code snippet of what I would add to view: Code: if($this->session->userdata('search_param')) Pagination/Validation: What to do? - El Forum - 04-28-2010 [eluser]pickupman[/eluser] I guess in the heart of what MVC stands for, then no. Looking at your code, there really doesn't seem to be a reason why it would have to be in the view. Looks like the same code would work in your controller. Pagination/Validation: What to do? - El Forum - 04-28-2010 [eluser]carvingCode[/eluser] [quote author="pickupman" date="1272479931"]I guess in the heart of what MVC stands for, then no. Looking at your code, there really doesn't seem to be a reason why it would have to be in the view. Looks like the same code would work in your controller.[/quote] I ended up leaving it in the controller. Was trying to find a way to correct the 'lag' caused by the redirect method. But... then I more closely read your previous reply and the docs... and replace 'refresh' with 'location'. Took care of it. As I'm not running the code on a Windows server, shouldn't be a problem. Thanks again. |