1

I am creating an ajax function to edit some settings.

these must be handled via the url

(i.e)

the url would be http://example.com/setting1/setting2/setting3

This works fine but. One of the settings is a url.

How could I pass this in this way?

1
  • 1
    You should consider switching the Ajax call to a POST request (instead of a GET request). This is simple to do in most AJAX toolkits. Commented Nov 22, 2010 at 16:11

2 Answers 2

5

this might work

$url = 'http://stackoverflow.com/questions/4245416/code-igniter-send-url-as-param';

$encoded = base64_encode($url);
//aHR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucy80MjQ1NDE2L2NvZGUtaWduaXRlci1zZW5kLXVybC1hcy1wYXJhbQ==

// Make your URL
$my_url = "site.com/controller/method/params/params/" . $encoded;

// redirect or whatever

$encoded_url = $this->uri->segment(4); // (or wherever the URL is)

$url = base64_decode($encoded_url);
// http://stackoverflow.com/questions/4245416/code-igniter-send-url-as-param
Sign up to request clarification or add additional context in comments.

1 Comment

+1. This is the only way I know to do that. But of course it is better to switch to POST request.
0

Look for the URI Class: http://codeigniter.com/user_guide/libraries/uri.html

From index.php/user/search/name/joe/location/UK/gender/male

You can get:

[array]
(
    'name' => 'joe'
    'location'  => 'UK'
    'gender'    => 'male'
)

Using:

$array = $this->uri->uri_to_assoc(3);

You can also find useful $this->uri->segment_array() .

3 Comments

I am aware of this. But, One of the params (lets say location is a website location) is a url you end up with ` index.php/user/search/name/joe/location/stackoverflow.com/users/383759/hailwood/gender/male` I am sure you can see the issue there...
Try with the segment_array(), you can ignore the first value if is something like /ajax/setting1/setting2. It will work.
That is not the issue. The issue is, the characters in the url are breaking it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.