CodeIgniter Forums

Full Version: Adding querystrings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]mattalexx[/eluser]
The problem with the whole "/controller/action/param1value/param2value/param3value" thing is, the parameters do not have keys and so flexibility is lost (what if I wanted to include param3 but not param1 or param2?). It would be cool if I could do something like this:
Code:
/controller/action/param1value/param3key:param3value
Or maybe this:
Code:
/controller/action/param1value?param3key=param3value
What's the best way to include variable parameters without making my life too difficult later on?

El Forum

[eluser]Randy Casburn[/eluser]
Have you looked at routing? With the ability to use wildcard routing thus:
$route['param3key/:num'] = "yourController/your_param3_method";
$route['param2key/:num'] = "yourController/your_param2_method";
$route['param1key/:num'] = "yourController/your_param1_method";

You can define as many as you need. This provides the flexibility you seek, just with slightly different terminology than you use. I think if you explore this it may work for you.

Randy

El Forum

[eluser]mattalexx[/eluser]
Thanks for your reply.

El Forum

[eluser]SeanJA[/eluser]
I usually use

desc1/param1/desc2/param2


Then I use the uri functions to pull the uri out and just see what is in the uri, then I can expand it without having any big rewrites.

El Forum

[eluser]Colin Williams[/eluser]
Check out $this->uri->uri_to_assoc(n) at http://ellislab.com/codeigniter/user-gui...s/uri.html

El Forum

[eluser]SeanJA[/eluser]
Exactly! Wink

El Forum

[eluser]mattalexx[/eluser]
[quote author="Colin Williams" date="1214216681"]Check out $this->uri->uri_to_assoc(n) at http://ellislab.com/codeigniter/user-gui...s/uri.html[/quote]
That's great. Thanks!