dot
dot

Reputation: 15660

Codeigniter URI segment has "/" embeded in the value

What's the best way to use a URI segment that has a "/" embedded in the value? for example, i'm passing a port number that looks like "abc1/1".

Thank you.

Upvotes: 1

Views: 151

Answers (1)

mamdouh alramadan
mamdouh alramadan

Reputation: 8528

Nice question BTW,

There are many ways to solve your problem. but what I prefer is to use:

$this->uri->uri_to_assoc();

I assumed the following url for your case:

http://localhost/nearest/nearest/index.php/welcome/testUri/x/1/abc1/1/gg

so you can do this in your controller:

$array= $this->uri->uri_to_assoc(3); // getting from third segment and after
var_dump($array);

which will output:

array (size=3)
  'x' => string '1' (length=1)
  'abc1' => string '1' (length=1) //here's your argument combined as key => value
  'gg' => boolean false

so simply you can get your segment then using this "key, value" array.

Upvotes: 1

Related Questions