2014-03-26 51 views
0

我是CodeIgniter的新手。在我的應用程序中,我有用戶輸入他的詳細信息的頁面我想在一個變量中獲取詳細信息(比如說只是名稱),並想在控制器文件中使用該變量。如何獲取輸入值在codeigniter中的控制器視圖

如何做到這一點?

+0

閱讀手冊,發佈您的表單數據到一個動作,然後訪問該表格數據來獲得你的價值。 –

+0

其實在這裏代碼它的東西像「form_open('register/add /');?>「 –

回答

0

http://ellislab.com/codeigniter/user-guide/libraries/input.html

$post = $this->input->post(); 
//on the controller you can access this and will return the array 
//of the post data you submitted 

您還可以通過變量名一樣讓他們:

$somedata = $this->input->post('some_data'); 

確保您的表單動作指向您的控制器以及。 :)

+0

好吧,讓我說我已經加載了數據\t $ this-> load-> view('register',$ data);現在我怎麼才能從這種形式的數據中得到一個特定的變量 –

+0

你真的必須閱讀docs並閱讀教程,這是一個完整的框架,您至少應該學習基礎知識,以便能夠編寫代碼。 –

0

名爲 「supername」

的方法

$supername = $this->input->post('supername', TRUE) ; 

以任何方法使用類$這個 - >

$this->supername = $this->input->post('supername', TRUE) ; 
使用內部本地使用表單值
0

在您的控制器中

$name= $this->input->post('name'); 

最好從一些關於Codeigniter的教程開始。

0

笨具有此Input class其中簡化了輸入時,它們在一些條件語句被使用。

要回答你的問題,對如何獲取用戶輸入的數據是:

$name = $this->input->post('name'); 

名稱值(這是你的字段的形式名稱)到變量名稱$名稱

你想知道該字段是否爲空?

嘗試:

if($name = $this->input->post('name')){ 
    //$name has the value of the name field and it is not empty, do something. 
}else{ 
    //$name has the value of the name field and it is empty, do something. 
} 

笨Input類也有XSS過濾功能,它會自動過濾輸入,以防止跨站點腳本攻擊。

所有你需要做的是:

它設置爲TRUE 你的config/config.php文件

$config['global_xss_filtering'] = TRUE; 
相關問題