[英]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.