CodeIgniter Forums
Routing issue - again! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Routing issue - again! (/showthread.php?tid=19851)



Routing issue - again! - El Forum - 06-20-2009

[eluser]jdav3579[/eluser]
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:
blah/page/index/CONTACT-US/thanks

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

Any help kindly appreciated!!


Routing issue - again! - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
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
Code:
$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


Routing issue - again! - El Forum - 06-20-2009

[eluser]jdav3579[/eluser]
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!!!


Routing issue - again! - El Forum - 06-20-2009

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

And I quote...
Quote:
Code:
$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


Routing issue - again! - El Forum - 06-20-2009

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


Routing issue - again! - El Forum - 06-20-2009

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