CodeIgniter Forums

Full Version: Routing issue - again!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I am fairly new to code igniter and cant seem to get my head around the uri routing thing. I have read numerous threads here but still can't seem to apply it to my own problem.

I think it should be straight forward to do, but just dont get it.
I have the following routing:
$route['page/index/CONTACT-US/:any'] = "page/contact";
so if the url is blah/page/index/CONTACT-US everything gets sent to this page/contact

but I also want to be be able to pass in parameters.
The contact function its like this

function contact($msg=null){}

I just want to pass the paramters into the function so for example:

then the function would get "thanks" in the msg variable.

Any help kindly appreciated!!

El Forum

Wrap the :any in brackets, and then change the right hand side of the expression to use $1 for the first variable (and $2 for the next and so on)

So you'll want something like
$route['page/index/CONTACT-US/(:any)'] = 'page/contact/$1';

Also, not sure if you want the contact us string to be upper case, but I recommend lower case
Also, you could probably get rid of index from the rule as well

Oh, and welcome to CI Smile

El Forum

Thanks very much for that! :-) i have spent ages trying to figure it out. It was just the user guide does not put the brackets on! but when I did put them on it worked! Thanks very much!!!

El Forum

[quote author="jdav3579" date="1245558407"]It was just the user guide does not put the brackets on![/quote]

And I quote...
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to the function.

That sure looks like some brackets to me Wink
You must have stopped reading after the first example, which doesn't have any

El Forum

ha! I think now I see where I was going wrong! I was looking at this one:
$route['product/:any'] = "catalog/product_lookup";
Cheers! :-)

El Forum

It's ok, I'm sure you'll remember to read the whole page next time you get stuck Wink