![]() |
Default Method for Controllers - 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: Default Method for Controllers (/showthread.php?tid=22276) |
Default Method for Controllers - El Forum - 09-03-2009 [eluser]Unknown[/eluser] I put my controllers in subfolders and I'm trying to modify the routes to set a default method for all controllers. Here is what I have: Code: $route['(:any)'] = "$0/dashboard"; This works, until I try and access any method other than dashboard, then it gives me a 404. Default Method for Controllers - El Forum - 09-03-2009 [eluser]Nick Husher[/eluser] Because it's probably looking for whatever your function name is/dashboard. So if you were to look for /blog/archive, your router is translating that to /blog/archive/dashboard. Not really what you want. What you probably want to do is take a look at the CI_Router class and extend it with a MY_Router. I'm 85% sure that's where the default method for controllers is set to "index" Default Method for Controllers - El Forum - 09-03-2009 [eluser]jdfwarrior[/eluser] With routes, if you define a default route, it takes precedence over the other routes, which is what its supposed to do. If you use (:any), you have to manually create routes to everything else. They have to be created above the (:any) route in the route.php as well. For instance: Code: $route['blog'] = "blog"; Basically goes right down the list, if it finds it before (:any), it goes where it should, if it doesnt find it, it considers (:any) as an, "if all else fails, do this" Default Method for Controllers - El Forum - 09-03-2009 [eluser]brianw1975[/eluser] er.... Code: $route['(:any)'] = "$0/dashboard"; call me crazy but shouldn't $0 be $1 ? Default Method for Controllers - El Forum - 09-03-2009 [eluser]jdfwarrior[/eluser] [quote author="brianw1975" date="1252020556"]er.... Code: $route['(:any)'] = "$0/dashboard"; call me crazy but shouldn't $0 be $1 ?[/quote] I was wondering the same thing but he said it was working, so i just skipped that part and went on.. Default Method for Controllers - El Forum - 09-03-2009 [eluser]Chad Fulton[/eluser] $0 matches the entire string that matched the regex pattern, and since the pattern is (:any), $0 is the same as $1 in this case. If the pattern was index/(:any), then $0 would be (for example) "index/dashboard", whereas $1 would be "dashboard". |