views:

8

answers:

1

hello, basicly I would like to read url params in an array so finding params don't depend on their place in url

I have a url for seach with controller/action/paramA/valueparamA/paramB/valueparamB theses params are optional : I have direct url with search params inside

to read params from url we have to use action(valueparamA, valueparamB) but for me it seems really rigid I want to read parameters by their name, not by their place in url!

so I can have different urls like

urlA = controller/action?paramA=valueA 
*(or controller/action/paramA/valueA)*
urlB controller/action?paramB=valueB

than I can use with the same action, like we do with a form with $_POST array (it and $_GET[} seems always empty when direct url params) the best would be to have all parameters in an array[paramname=>paramvalue] like in a form

what I DON'T want is tu use differents actions for different parameters possibles! :)

the best I saw was to use juste on array like parameter :

controller/action/array[paramname=>paramvalue]

(http://stackoverflow.com/questions/1763508/passing-arrays-as-url-parameter) but it seems to complicate something basic : just read the normal url parameters like every framework knows :) with

url?nameparam=valueparam&...

hope there is a solution ! I begin tor eally like the light and quick of ci but sometimes (like for extending model) it seems a little "rigid" ;)

think in advance for any idea!

A: 

Yep the URI class provides this functionality in the form of

$this->uri->uri_to_assoc(n);

This returns an array containing all parameters (keys and values must be defined in the URL).

Full details can be found on the Codigniter Userguide:

http://codeigniter.com/user_guide/libraries/uri.html

DRL
big think mister!with $this->uri->assoc_to_uri(arrayparams) to construct the url it works perfect! :)when looking into forums I was afraid to have to "hack" with $get or expands modelyou made my day ! ;)
david
No probs :) please accept the answer if you are happy.
DRL