Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter routing when routing url starts with variable
#1

[eluser]Md. Ruzdi Islam[/eluser]
I am getting problem on codeigniter routing when routing url starts with variable like following -
Code:
$route['(:any)/(:any)']  = "home/index/0/N/DealsAmount/ASC/$1/$2";
i can to able to configure other routing url when i am passing values through url. Example: Following things work perfectly
Code:
$route['About-Us/Team'] = "aboutus/team";
$route['About-us/Jobs'] = "aboutus/jobs";
$route['About-Us/FAQ'] = "aboutus/faq";
But i use this url using varible like following --
Code:
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";

then it redirects to the home page that means this routing is not working here $route['(:any)/(:any)'] is working how can i able to rout these types of url can you please advise me.

Please reply soon it's really urgent.

Thanks Ruzdi
#2

[eluser]CroNiX[/eluser]
Route processing starts with your first route and see if it can match the url. If it can, it will route there, if not it will go to the next rule.

So, if your (:any)/(:any) rule comes first, it will actually match all routes and route to that controller, because the first (:any) will match, well, everything. That route should be dead last. You want to see if your other routes match first before sending it to a "catch-all" route.

The 2nd thing having to do with this is that if you have very similar routes where the main thing that differs is the number of segments, the route with the MOST segments needs to come before those with less.
Code:
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";

Your 2nd route here will never be triggered, because the first one will catch anything that the 2nd one should have received because again, the (:any) rule in the first rule will catch "anything", and that includes extra segments (because at this point the entire url is a string, not a CI "segment"). So the rule with 4 segments should come before the similar one with 3 so that if a request has 4 segments it will be triggered by that rule before trying to match the next one down the list.
#3

[eluser]Md. Ruzdi Islam[/eluser]
Thank you for your solution it really works and solve my problem. Many many thanks.




Theme © iAndrew 2016 - Forum software by © MyBB