在Codeigniter URL段中传递URL


Passing URL in Codeigniter URL segment

我想传递一个urlhttp://example.com/test?a=1&在代码点火器的url段中b=2。

我正试着通过这样的东西http://myurl.com/abc/http://example.com/test?a=1&b=2并得到"http://example.com/test?a=1&b=2"url。最好的方法是什么?

application/config/config.php中将URI协议设置为REQUEST_URI,如下所示:

$config['uri_protocol'] = 'REQUEST_URI';

然后使用GET方法:

$this->input->get('a');

编辑:

http://example.com/test?a=1&b=2不是编码的URL,这是不可能的。因此,首先,我将使用urlencode函数对URL进行编码,如下所示:

urlencode('http://example.com/test?a=1&b=2');

它返回类似于:http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2

所以我会这样传递URL:

http://myurl.com/?url=http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2

然后用get方法得到一个示例URL。

$this->input->get('url');

使用此技术获取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");

在段中传递urlendex()的URL,然后用自己的(MY_*)类进行解码:

application/core/MY_URI.php:

<?php
class MY_URI extends CI_URI {
    function _filter_uri($str)
    {
        return rawurldecode(parent::_filter_uri($str));
    }
}
// EOF