Welcome Guest, Not a member yet? Register   Sign In
Controller's Index Action with Parameter
#1

[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.
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB