Welcome Guest, Not a member yet? Register   Sign In
URLs as parameters
#1

[eluser]marlar[/eluser]
Hi,

I need to supply a URL as a parameter, like:

mysite.com/bookmark/add/http://www.example.com/somepage.html


Here bookmark/add is the controller/function, and the rest is the parameter.

But CI thinks it's all a bunch of segments so it doesn't work.

What can I do about this?

Regards,
Martin
#2

[eluser]Matthew Lanham[/eluser]
Im no expert in CI yet, so im just putting this out there:

As a quick work around you could use the function:

$this->uri->uri_string()

To return a string of the url, this should look like:

bookmark/add/http://www.example.com/somepage.html

Then you could use a simple substr, or str_replace...

i.e.:

$string = $this->uri->uri_string();
$url = str_replace('bookmark/add/','', $string);

this should return:
http://www.example.com/somepage.html


Its a kinda long winded way of doing it, and im sure someone else will come up with a solution, but it might be a quick fix for you.
#3

[eluser]marlar[/eluser]
Thanks!

That will probably do it. Must check as soon as I get time.
#4

[eluser]ejangi[/eluser]
You could also urlencode() the URL:
Code:
$my_link = 'bookmark/add/'.urlencode('http://www.example.com/somepage.html');
// Which will give you:
// bookmark/add/http://www.example.com/somepage.html
#5

[eluser]marlar[/eluser]
Yes, but I want sometimes to manually add the URLs in the address field of the browser :-)
#6

[eluser]marlar[/eluser]
[quote author="swanweb" date="1197256418"]Im no expert in CI yet, so im just putting this out there:

As a quick work around you could use the function:

$this->uri->uri_string()[/quote]


This works great, except that I have to add

$url = str_replace(':/', '://', $url);

because the double slash is translated by the browser to a single slash.




Theme © iAndrew 2016 - Forum software by © MyBB