views:

43

answers:

3

The Url Segment in Codeigniter seems simple and easy to follow... however, I am creating a search feature which requires the Url Segment to be dynamic.

If I add a Search function within my Main Class, I would have to include the "Welcome" class to the Url Address: http://example.com/index.php/welcome/search/stuff-i-want-to-search/

However, I want the Url to be: http://example.com/index.php/search/stuff-i-want-to-search/

That is without the "Welcome" in the Url, and most likely also without the index.php

I thought I could achieve this by creating a new class file called Search. I am able to load the file but when I attempt to search, I end up in a 404.

Please advise.

A: 
Ross
+1  A: 

Hi,

In CI, URI Routing will do this for you.

$route['search/:any'] = "welcome/search/$1";
paulrajj
+1  A: 

Using $route['search/:any'] = "welcome/search/$1"; is a risky process, because :any can take in anything..

I suggest using Regular Expressions, which is safer to use.

$route['search/([a-z_A-Z]+)'] = 'welcome/search/$1';
tpae