CodeIgniter Forums
Routes help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Routes help (/showthread.php?tid=25843)



Routes help - El Forum - 12-28-2009

[eluser]PHP Creative[/eluser]
Hi

I was wondering if anybody could help me. I have the following url.

http://www.test.com/store/dvds/34

store = controller name
dvd = category name (hundreds of possible categories so would be hard to create an array)
34 = id of product

Basically I can route the first URI (category) to a function inside store called categories doing the following

$route[store/(:any)'] = "store/categories/$1";

But can’t re-route the product id to a function called product_info. Tired the following:

$route[store/(:any)/(:any)'] = "store/product_info/$1";

I would really appreciate any help.

Thanks a million


Routes help - El Forum - 12-28-2009

[eluser]janogarcia[/eluser]
Hi, try this

Code:
$route['store/:any/(:any)'] = "store/product_info/$1";

Or if you prefer to fetch each segment at controller level,

Code:
$route['store/:any'] = "store/product_info";

Then, in your controller constructor or in the product_info() method you would fetch each segment as folllows:

Code:
$product_category = $this->uri->segment(2);
$product_id = $this->uri->segment(3);