![]() |
A better way to handle params? - 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: A better way to handle params? (/showthread.php?tid=32656) |
A better way to handle params? - El Forum - 07-30-2010 [eluser]davewilly[/eluser] Hey guys, I'm finding it a bit of a messy affair dealing with multiple params on a site I'm rebuilding in CI. I have a URL like www.site.com/stag-do/bristol/packages/1 and have been struggling to handle it in a clean manner without some ugly if/elseif. I had thought it would be a case of a nice switch statement. I've had to cascade if/elseif statement, with what I would consider the wrong logical flow to handle it. My psuedo code is this: if a package (ie. /1, /2 etc) param is set ---- Test it in a switch and display package details page elseif packages segment isset and is equal to 'packages' ---- Show the packages page elseif location segment is set, and location segment is equal to 'bristol' and packages segment is not set.. ---- Show location page else ---- 404 I would really appreciate if someone has a better solution. Perhaps this is more of a general PHP questions opposed to a CI specific question! Here is code from my controller, the method I am refering to is bristol() Code: <?php Thanks, Dave A better way to handle params? - El Forum - 07-30-2010 [eluser]John_Betong[/eluser] I would be tempted to look at routing the url to specific controller. Try this link: URI Routing A better way to handle params? - El Forum - 07-30-2010 [eluser]davewilly[/eluser] [quote author="John_Betong" date="1280509624"]I would be tempted to look at routing the url to specific controller. Try this link: URI Routing [/quote] John, thanks. I'm playinmg with the routes now. I just hope I can do with having dozens upon dozens of $route[] rules. Dave A better way to handle params? - El Forum - 07-30-2010 [eluser]mddd[/eluser] If I get you correctly, there are basically 3 pages: 1- a page to show info about a city 2- a page to show a list of packages 3- a page to show info about a specific package. I would make the urls as short as possible, like so: /stag-do/bristol : show page type 1 /stag-do/bristol/packages : show page type 2 /stag-do/bristol/2 : show page type 3 (if you like this could also be /stag-do/bristol/packages/2 but why make it longer than neccessary) You could do all the checking in your _remap function in the stag_do class: Code: function _remap() A better way to handle params? - El Forum - 07-30-2010 [eluser]davewilly[/eluser] mddd, Thanks there, all very clear. Appreciate it, I hadn't thought of reducing the URL by a segment, sounds a good idea. atb, Dave |