CodeIgniter Forums
I need some help I wanna pass this parameter to a Controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: I need some help I wanna pass this parameter to a Controller (/showthread.php?tid=62954)



I need some help I wanna pass this parameter to a Controller - abebatista - 09-11-2015

I wanna pass this parameter to a Controller in CI, for instance  {Controller}/{View}/{Params} , where {Params} I need it to be like code1+code2+code3 , is this possible ?  

for instance : Players/GetPlayersInfoByIdList/id1+id2+id3

or there is a better way to do it ?


RE: I need some help I wanna pass this parameter to a Controller - russ_kern - 09-11-2015

Can you not do it exactly as you have it and then explode it out when you get it into your controller?

Actually, a little more detail on what you are doing may be helpful.
R


RE: I need some help I wanna pass this parameter to a Controller - RobertSF - 09-11-2015

I've not had to do it, so I haven't checked it out, but from the documentation it seems that you can have any or at least some number of additional URL segments, which will be interpreted just like the third. That is...

Code:
http://www.example.com/controller/method/arg1/arg2/.../argn

Presumably then, your method would expect those arguments, with
Code:
function foo ($arg1, $arg2, $arg3='', $argn=false)
{
   // code
}

If it doesn't work that way, you should still be able to receive the set of arguments as a single argument, which as russ_kern pointed out, you can put into an array with the explode statement.


RE: I need some help I wanna pass this parameter to a Controller - Wouter60 - 09-12-2015

Passing the variables as one string with seperators is a good idea, but there's another way:
PHP Code:
function test($name){
 
   $uri_seg $this->uri->uri_to_assoc();

 
   foreach($uri_seg as $para){
 
       // Do something with each of the URI segments passed in here after $name
 
   }

You can even define a default value for every parameter.
See CI's documentation: http://www.codeigniter.com/userguide3/libraries/uri.html?highlight=uri_to_assoc#CI_URI::uri_to_assoc