2013-06-27 54 views
0

在代碼點火器中,我使用的是內置的URL類代碼點火器 - 將URL放入URL參數

我在這裏遇到問題。我想要在當前網址中包含引薦來源網址。

實施例,本地主機/ from_referrer//account/verify/email/b4a98ddd44

/account/verify/email/b4a98ddd44是,我想要加入到當前的URL的URL。

我試過urlencode()。它看起來像這樣

/account/login/from/%2Faccount%2Fverify%2Femail%2Fb4a98ddd44 

但它不起作用。 CI假設我想去

/account/login/from//account/verify/email/b4a98ddd44 

,但我想去

/帳號/登錄/從/ /account/verify/email/b4a98ddd44(一個突出的就是參數)

人,你有任何想法如何做到這一點?

回答

0

,如果您的網址總是以相同的網段開始,你可以嘗試讓各階層在一個數組和剝離小號一開始你就不需要。

$segs = $this->uri->segment_array(); 
unset ($segs[0]); //unset /account 
unset ($segs[1]); //unset /login 
unset ($segs[2]); //unset /from 

$uri = implode('/', $segs); 
echo $uri; // echoes "account/verify/email/b4a98ddd44" 

另一可能解決方案: 這不是一個awnser你的問題,但也許一(尤爲明顯)解決。

爲什麼不使用http referer結合codeigniter閃存數據? 當用戶進入登錄頁面,在控制器設置閃光燈數據

$this->session->set_flashdata("referer",$_SERVER['HTTP_REFERER']); 

那麼用戶登錄後,就可以使用這個檢索值再次

$uri = $this->session->flashdata("referer"); 

flash data codeigniters manual

+0

我認爲更好的方法是使用閃存數據:P –

0

這裏是只是一個想法

嘗試-更換/爲您引用網址像

$referrer= str_replace('/', '-', '/account/verify/email/b4a98ddd44'); 

所以網址將變爲像這樣

account/login/from/-account-verify-email-b4a98ddd44 

現在,在您account controller's登錄功能得到這個像

function login(){ 
$referrer= str_replace('-','/',$this->uri->segment(4)); 
} 

現在你可以在很多方面像你可以散列URL,然後在您的網址添加,但如果你在URL追加/account/verify/email/b4a98ddd44 CI將會把它當作個人PARAMS像

account => is the uri segment(4); 
verify=> is the uri segment(5); 
email=> is the uri segment(6); 
b4a98ddd44=> is the uri segment(7); 

所以,你這樣做需要讓沒有/一個字符串,因此它會在一個URI段

希望這是有道理的