Welcome Guest, Not a member yet? Register   Sign In
Passing Params to Index of Controller
#1

[eluser]garaget[/eluser]
I have been working with CI for only a week, so please bear with me.
I have been passing values to functions in my classes with no problem.
, but what I want to do is pass values to the index of my controller without typing out

Code:
/class/index/value

I want it to look like

Code:
/class/value

I was thinking it is just something to with the .htaccess file I need to rewrite to? Thanks to anyone who can help.
#2

[eluser]Grahack[/eluser]
try to add this rule in your config/routes.php file (see routing in the docs)
Code:
$route['class/(\d+)'] = "class/index/$1";
#3

[eluser]garaget[/eluser]
:vampire: Excellent, This is why CI rox, great community. Sorry I could of swore I read that page a few times.. should have paid more attention. Muchos Gracias!
#4

[eluser]xwero[/eluser]
I don't know if it works but in the routes file you could use a regular expression where you add all your methods for that controller with a negative lookahead.
Code:
$route['class/(?!method1|?!method2)'] = 'class/index/$1';
#5

[eluser]garaget[/eluser]
even better, just in case i have a numerical function I suppose
#6

[eluser]xwero[/eluser]
I was thinking more in the direction of a word value. I think CI will try to parse it as a function.
class/value will look like
Code:
class class {
  function value(){}
}
The idea behind the regular expression is every value that is not one of the methods will be added after index/. This would allow you to add multiple values but like i said before it's untested.




Theme © iAndrew 2016 - Forum software by © MyBB