![]() |
Routing, regular expressions and category paths... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Routing, regular expressions and category paths... (/showthread.php?tid=32516) |
Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]Maarten Troonbeeckx[/eluser] You guys, I'm trying to parse the following URLs: Code: http://my.shop.be/browse/electronics/hifi The first one shows all products in subcategory hifi (parent category is electronics). The second one show the product Sony Bravia with productID = 20. My routes look like this (RegExhibit to the rescue ![]() Code: $route['browse/([a-zA-Z0_9\/]+)'] = 'browse/category/$1'; My browse controller is setup like this: Code: function category($path); Problem is that, instead of one parameter $path which equals 'electronics/hifi' in the both functions, it is passed as two parameters, i.e. 'electronics' and 'hifi'. This is because of this line of code in the Router class on line 289: Code: $this->_set_request(explode('/', $val)); Is this maybe a situation where _remap() comes into place? Any ideas on how I can get 'electronics/hifi' passed into just one parameter $path in my controller functions? Tnx in advance. M. Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]mddd[/eluser] You could get the variables in the functions themselves: Code: function category() Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]Jelmer[/eluser] Also, for more general debugging, try this order for your routes: Code: $route['browse/([a-zA-Z0-9\/]+)/([0-9]+)/[a-zA-Z0-9]+'] = 'browse/product/$2/$1'; The routes are matched against the URI in the order you define them in. So the rule you put first (I put second above) would already match the URI before the other rule would ever be considered. If you got a very specific rule and a more general catch-all type rule: always put the specific rule before the general rule. Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]tranc huc[/eluser] thanks Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]Maarten Troonbeeckx[/eluser] I can work with that ![]() Tnx! Routing, regular expressions and category paths... - El Forum - 07-26-2010 [eluser]Maarten Troonbeeckx[/eluser] I've implemented it like this: Code: public function _remap($method) |