URI Routing, best way to do that |
[eluser]daweb[/eluser]
I everybody, I have to read from a DB some records and I have to build my dynamic query based on uri segments. (and some $_POST values...) I have, for example: http://www.my-site.com/buy http://www.my-site.com/sell http://www.my-site.com/buy/car http://www.my-site.com/sell/motocycle/red http://www.my-site.com/buy/dog/big/italy...g-name/123 I want to build the query in just one controller... Is it the right way to make: ? $route['buy/(:any)/(:any)/(:any)/(:any)/(:any)'] = 'home/$5'; $route['sell/(:any)/(:any)/(:any)/(:any)/(:any)'] = 'home/$5'; $route['buy/(:any)/(:any)/(:any)/(:any)'] = 'home/$4'; $route['sell/(:any)/(:any)/(:any)/(:any)'] = 'home/$4'; $route['buy/(:any)/(:any)/(:any)'] = 'home/$3'; $route['sell/(:any)/(:any)/(:any)'] = 'home/$3'; $route['buy/(:any)/(:any)'] = 'home/$2'; $route['sell/(:any)/(:any)'] = 'home/$2'; $route['buy/(:any)'] = 'home/$1'; $route['sell/(:any)'] = 'home/$1'; $route['buy'] = 'home'; $route['sell'] = 'home'; What's the best solution to make this? I'm very sorry about my english... Will be better tomorrow... :-)
[eluser]xwero[/eluser]
I think you don't have to do any routing for this. You just check how many segments there are and take action based on that data Code: function buy()
[eluser]daweb[/eluser]
thank you xwero, just a question... if buy and sell are dynamic too, can I use your code in my default controller? is the right way? PS. This quesions 'cause I'm using Ocular library first time, and... it's difficoult for me. Thank you so much...
[eluser]xwero[/eluser]
If buy and sell are dynamic too you could do something like Code: function home()
|
Welcome Guest, Not a member yet? Register Sign In |