I want to pass a url like http://example.com/test?a=1&b=2 in url segment of codeigniter.
I'm trying to pass something like this http://myurl.com/abc/http://example.com/test?a=1&b=2 and get the "http://example.com/test?a=1&b=2" url. What should be the best way to do this?
Set your URI protocol to REQUEST_URI
in application/config/config.php
, like this:
$config['uri_protocol'] = 'REQUEST_URI';
then use GET
method:
$this->input->get('a');
EDIT:
Since http://example.com/test?a=1&b=2 is not encoded URL, it isn't possible. So first, I would encode URL with urlencode function like this:
urlencode('http://example.com/test?a=1&b=2');
it returns something like: http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2
So I would pass the URL like this:
http://myurl.com/?url=http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2
then get an example URL with GET method.
$this->input->get('url');
Here is a link to an article that answers this questin - http://wildlyinaccurate.com/segment-based-urls-with-query-strings-in-codeigniter-2/
Remember Google is you best friend.
Use this technique to get the URL
$url = "http://example.com/test?a=1&b=2";
$segments = array($controller, $action, $url);
echo site_url($segments);
// or create a anchor link
echo anchor($segments, "click me");
Pass urlendode()'d URL in segment and then decode it with own (MY_*) class:
application/core/MY_URI.php:
<?php
class MY_URI extends CI_URI {
function _filter_uri($str)
{
return rawurldecode(parent::_filter_uri($str));
}
}
// EOF