繁体   English   中英

在Codeigniter URL段中传递URL

[英]Passing URL in Codeigniter URL segment

我想在codeigniter的网址段中传递一个类似于http://example.com/test?a=1&b=2的网址。

我正在尝试传递类似http://myurl.com/abc/http://example.com/test?a=1&b=2的内容,并获得“ http://example.com/test?a= 1&b = 2“网址。 最好的方法是什么?

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方法获取示例网址。

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

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

应用/核心/ MY_URI.php:

<?php

class MY_URI extends CI_URI {

    function _filter_uri($str)
    {
        return rawurldecode(parent::_filter_uri($str));
    }
}

// EOF

这是回答此问题的文章的链接-http://wildlyinaccurate.com/segment-based-urls-with-query-strings-in-codeigniter-2/ 记住Google是您最好的朋友。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM