tags:

views:

25

answers:

1

This is my first time getting my hands dirty with CI so I'm getting a little confused.

I'm wanting to accomplish a couple things with my question. First of all, I'd like to always use the default controller without having it to appear in the url. For example, I created a new class named after my site (Example.php) and that works fine. However, if I want to call the search function in my controller I then have to go to example.com/index.php/example/search/.

The second thing I want to accomplish is when I run a search I'll get a nice looking url like so: example.com/search/This+is+a+search (I haven't gotten to removing the index.php portion but I know to use a htaccess). I'm not worried about the actual mechanics of the search, just that I'd like to format the url in this way.

I originally experimented with using a Search class but that found that it doesn't allow me put the search in the url because the second parameter should be a function and not the extra stuff.

Thanks for any help.

A: 

In application/config/routes.php file add $route to redirect everything to your controller.

Something like this:

$route['([^\/]+)'] = 'content/index/$1';
$route['([^\/]+)\/([^\/]+)'] = 'content/index/$1/$2';

This will redirect urls like example.com/A and example.com/A/B to a controller named content. Parameters A and B will be passed to method index.

Marko Dumic
Thanks so much. After looking through the URI routing part of the guide I managed to do the same thing with wildcards. I'm not great at RegEx. Got me going in the right direction now.
Hatbocs