spiderwell Posted January 2, 2013 Share Posted January 2, 2013 Happy New Year everyone! OK so I am sure my problem is easily resolved, but it isn’t obvious to me so maybe one of you experts can help. I have a controller called products, with a bunch of methods, index shows all products by category, there is a method azproducts does the same thing but groups by letter, then i have a search method also. then each product has its individual view in the view method. here are my routes: $route[‘products’] = ‘products’; $route[‘products/addtobasket/(:any)’] = ‘products/addtobasket/$1’; $route[‘products/view/(:any)’] = ‘products/view/$1’; $route[‘products/azproducts/(:any)’] = ‘products/azproducts/$1’; $route[‘products/search/(:any)’] = ‘products/search/$1’; $route[‘products/(:any)’] = ‘products/index/$1’; Now I think the issue is to do with the bottom line, as if I remove ‘index’ from $route[‘products/(:any)’] = ‘products/index/$1’ it returns with a 404, but if i leave it in, it works. However with it left in, the search page then fails to work and routes to the index method instead. does anyone have any ideas what I am doing wrong? I have posted this also on EllisLabs Codeigniter forum, but I think this site has better 'footfall' Thanks Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/ Share on other sites More sharing options...
salathe Posted January 2, 2013 Share Posted January 2, 2013 Are you just going to /products/search when searching? Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/#findComment-1402734 Share on other sites More sharing options...
spiderwell Posted January 2, 2013 Author Share Posted January 2, 2013 yes the form posts to products/search but it seems to redirect to products/index Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/#findComment-1402750 Share on other sites More sharing options...
Christian F. Posted January 2, 2013 Share Posted January 2, 2013 I don't know how the router is set up, but I suspect it has something to do with the /(:any) bit not being optional. Worth having a look at, at least. Also, what happens if you put the problematic line on top? Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/#findComment-1402806 Share on other sites More sharing options...
cpd Posted January 2, 2013 Share Posted January 2, 2013 You don't need to define every possible link e.g. $route['products/view/(:any)'] = 'products/view/$1'; Provided there is a controller called Products and a method called view it will get executed as this is the default routing method - which can be reconfigured if you wish - and any arguments will be passed as parameters. Secondly, when defining routes it'll take the last defined route and overwrite any conflicting routes. In your case you have: $route['products/search/(:any)'] = 'products/search/$1'; $route['products/(:any)'] = 'products/index/$1'; CodeIgniter sees the second one and re-routes anything with "products" in to products/index/$1 i.e. every single method you've defined will now be redirected to your index method Taking into account my previous comments, remove both. Edit: Apologies for all the edits, spotted a load of grammar and language errors. Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/#findComment-1402810 Share on other sites More sharing options...
spiderwell Posted January 7, 2013 Author Share Posted January 7, 2013 hey thanks for the reply on this, sorry i didnt spot it earlier!! Link to comment https://forums.phpfreaks.com/topic/272609-codeigniter-routes-problem/#findComment-1403915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.