CodeIgniter Forums
Controller's Index Action with Parameter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Controller's Index Action with Parameter (/thread-21825.html)



Controller's Index Action with Parameter - El Forum - 08-21-2009

[eluser]ciuser99[/eluser]
I just came across something kind of interesting. It's not necessarily a bug but it threw me off for a while. I'm using the latest Code Igniter (v.1.7.1). If your controller index action contains a parameter and you have any other actions in the same controller with a parameter and if you also place the index route in the routes.php file before the other actions, the page will always go to the index action. The other actions will be ignored unless you place the other routes ahead of the index route in the routes.php. This may be by design or perhaps it's just bad practice to place a parameter in the index action. Does anyone have any comments on this? Thanks.


Controller's Index Action with Parameter - El Forum - 08-21-2009

[eluser]Robert Wallis[/eluser]
You are very close, it actually doesn't have to do with the presence of parameters in index(). It's all about routes.

The routes work on a first matching basis. So if the index route has an :any at the end of it, the page name won't be used. The best solution is the one you found to put the other actions above your index. You could also exclude the action name in a regex on the index route.