Welcome Guest, Not a member yet? Register   Sign In
Routing question: possible to create a catch-all when not calling a function?
#1

[eluser]Fabdrol[/eluser]
Hi guys.

I've got the following methods in my "Search" controller.:

Code:
search/index => search homepage
search/web ($term) => web results
search/images ($term) => images results
search/news ($term) => news results

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!
#2

[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.
#3

[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!
#4

[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.
#5

[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!




Theme © iAndrew 2016 - Forum software by © MyBB