• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if the parameter value has slash, how can i pass it to codeigniter url

For example, the parameter value is "dump / dummer"

I want to pass this parameter value to the codeigniter site, http://mycisite.com/get/.

http://mycisite.com/get/dump / dummer

Of course, it would not work

urlecode('dump / dummer') and then pass it to http://mycisite.com/get/ still not work.


"dump \/ dummer"
Now try urlencode


CodeIgniter's URL helper also has a function that would work.

url_title('Dumb / Dumber');

You could base64_encode it, then base64_decode it at the other end:

echo site_url('controller/method/' . base64_encode($var));

function method($var)
    $var = base64_decode($var);

You could also try adding it here, but not recommended!
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'/;


thanks i replace / with - before passing the parameter, and replace it back

but url_title seems to be a more universal solution. I will check this out.

base64_encode is the approach i was looking for. Thanks for all your help.

base64_encode has / = which are not valid url characters in CI.

So I could use the str_replace, say replace / with _ replace = with -. and then replace them back and base64_decode it.

Is this the right way to pass the parameter value in url in CI? It has been a trouble for CI that sometimes we need pass values in url and these values have the invalid characters. And I don't want to loose the universal set up for the valid uri characters.

Of course, this way, we get around the uri character validation checking, so we need be extra careful, validation checking these values.

I have a similar problem.

I'm writing an application that uses pre existing product data eg: BA/RL

I have setup a controller with a view function that takes the 3rd segment as the product ID, works fine for product ID's without the / in eg: ANT

Whats the best way to hadle this?

"encode" the value before pass
$value = str_replace('=', '-', str_replace('/', '_', base64_encode($value)));

"decode" the value after receive
$value = base64_decode(str_replace('-', '=', str_replace('_', '/', $value)));

You can write a helper like this.

I don't do this on the values input by the end users.

And after receive the value, I validate the value again.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.