• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI Routing with more than one variable?

#1
[eluser]juddmuir[/eluser]
Hi,

Is it possible to set up a routing rule that took e.g.
example.com/products/category_id/product_id
and passed BOTH the category_id and the product_id to whatever function?

In the User Guide, there's an example for only one variable:
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

Thanks in advance for any replies.

#2
[eluser]Lukifer[/eluser]
I haven't tested it myself, but it works much like regular expressions, so you should be able to use:

Code:
$route['product/(:num)/(:num)'] = "products/$1/$2";

If that doesn't work, the normal regex version should:

Code:
$route['product/([0-9]+)/([0-9]+)'] = "products/$1/$2";

#3
[eluser]sheldonnbbaker[/eluser]
Just add the rule in your routing config (with regular expressions or whatever) and then you can grab the variables with uri->rsegments().

#4
[eluser]juddmuir[/eluser]
Thanks for your replies!
I used Lukifer's first option, worked a charm :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.