2014-06-26 22 views
0

我期待將一個參數傳遞給我的函數。頁面是sub.mainsite.com/profile/change-passwordCodeigniter - 獲取一個uri參數

該配置文件是控制器和更改密碼是其中的功能。現在,如果用戶首次登錄時想要傳遞change-password/first,那麼系統可以將它們重定向到主頁而不是配置文件頁面。

$uri_params = I_WANT_TO_SEE_IF_FIRST_IS_SET; 
+1

在CI URI參數被稱爲段。你知道'$ this-> uri'(在控制器動作中)嗎? 「CI_URI」的實例?那有一個'$ segments'的公共財產? (http://ellislab.com/codeigniter/user-guide/libraries/uri.html) –

回答

1

只要這樣做。

$uri = $this->uri->segment(3)
這將檢索更改密碼$uri_params = $uri .'/first';

+0

謝謝Raheel :) – Adeel

0

我不知道這是否是你期待什麼。但是,在您的控制器中,

public function change_password($first = FALSE) { 
    if ($first == FALSE) { 
     redirect("profile"); 
    } else { 
     redirect("home"); 
    } 
} 

通過在控制器中設置默認值,可以使其成爲可選項。因此,如果URL中的change_password之後沒有任何值,則它將分配$first = FALSE