CI訪問表單數據的方法

主要有下面幾個方法:數組

  • $this->input->post()
  • $this->input->get()
  • $this->input->cookie()
  • $this->input->server()

 1. $this->input->post()cookie

第一個參數爲你想要獲取的 POST 數據名:post

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

若是獲取的數據不存在,該方法返回 NULL 。this

第二個參數可選,用於決定是否使用 XSS 過濾器對數據進行過濾。 要使用過濾器,能夠將第二個參數設置爲 TRUE spa

若是不帶任何參數該方法將返回 POST 中的全部元素。server

若是但願返回 POST 全部元素並將它們經過 XSS 過濾器進行過濾, 能夠將第一個參數設爲 NULL ,第二個參數設爲 TRUEget

$this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$this->input->post(NULL, FALSE); // returns all POST items without XSS filter

若是要返回 POST 中的多個元素,將全部須要的鍵值做爲數組傳給它:input

$this->input->post(array('field1', 'field2'));

和上面同樣,若是但願數據經過 XSS 過濾器進行過濾,將第二個參數設置爲 TRUE:it

$this->input->post(array('field1', 'field2'), TRUE);
相關文章
相關標籤/搜索