Routing question: possible to create a catch-all when not calling a function? - 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: Routing question: possible to create a catch-all when not calling a function? (/showthread.php?tid=23258) |
Routing question: possible to create a catch-all when not calling a function? - El Forum - 10-05-2009 [eluser]Fabdrol[/eluser] Hi guys. I've got the following methods in my "Search" controller.: Code: search/index => search homepage I want a route to catch everything behind "search/" and route it to search/web. So when someone calls search/anything, it gets routed, but not when someone calls just "search" or "search/web/term" or "search/images/term" or "search/news/term". I might sound a bit unclear, but I hope you guys understand my question. Thanks in advance! Routing question: possible to create a catch-all when not calling a function? - El Forum - 10-05-2009 [eluser]jdfwarrior[/eluser] There are, to my knowledge, two options. I am not completely clear as to what you want to do when someone calls the 'search/anything'. Does 'it gets routed mean, it calls another function and it searches for that term? Or does it redirect to a 404? Anyway. Option #1: Create all routes. You can do something like.. $route['search/web/$1'] = 'search/web/$1'; .. .. .. other functions $route['search/(:any)'] = 'search/index'; And that will take anything that is not a route to a function, redirect to the index function instead, or whatever function you want. Option #2: Use _remap. You can create a _remap function within the controller itself and then make it direct to the functions that are available, and anything else passed in, does whatever you want, a redirect, maps to another function, etc. Routing question: possible to create a catch-all when not calling a function? - El Forum - 10-06-2009 [eluser]Fabdrol[/eluser] Thanks, jdfwarrior... I think that tackled the problem. (option 1) But I'm still quite interested in the _remap function. Gonna check it out in the user guide! Thanks again! Routing question: possible to create a catch-all when not calling a function? - El Forum - 10-06-2009 [eluser]jdfwarrior[/eluser] [quote author="Fabdrol" date="1254858485"]Thanks, jdfwarrior... I think that tackled the problem. (option 1) But I'm still quite interested in the _remap function. Gonna check it out in the user guide! Thanks again![/quote] You did read though that, any function you create in the controller from now on has to have a route created for it, above the (:any) route correct? Otherwise it's not going to work. Routing question: possible to create a catch-all when not calling a function? - El Forum - 10-06-2009 [eluser]Fabdrol[/eluser] Yep, It works like a charm. Yet so simple, I was bumping my head against the wall wondering why I didn't think of that! ;-) Thanks! |