這是正確的嗎?注意第二個選項,我使用$ _POST變量傳遞表單值。鑑於第一個選項,我爲每個表單字段調用和分配變量。Codeigniter:將視圖中的表單數據傳遞給控制器
我已經看到了這個...
<validation code> ....
$todo = array(
'name'=>$this->input->post('title'),
'description'=>$this->input->post('description')
);
$this->Todo_model->add($todo);
但我也看到了下面......
$records['email'] = "trim|required|min_length[4]|xss_clean";
...
...
$this->validation->set_rules($records);
if ($this->validation->run())
{
$this->account_model->saveAccountSettings("sam", $_POST);
$this->session->set_flashdata('message', 'Done!');
redirect('account/settings');
} else {
...
}
這
這裏不理解這條線。 $ account ['email'] = $ this-> validation-> email; 它在做什麼?我的意思是我看到它正在驗證該領域,第一個領域是在哪裏發揮作用? – luckytaxi 2010-01-07 14:37:16
你可以使用$ this-> validation->就像使用$ this-> input-> post('something')一樣。在通過驗證框架運行後,它會爲您提供POST的價值,同時考慮trim和XSS等內容。 – Parrots 2010-01-07 14:44:58
是否必須在第一行定義「某些東西」?看看它說$ fields ['email'] ...就像我只設置了電子郵件的「驗證規則」,我可以做$ this-> validation-> id,是嗎? – luckytaxi 2010-01-07 14:49:27