我通過URL傳遞變量$id
,並以表單形式更新加載數據,但是當我要驗證表單時,無法識別值$id
。驗證CodeIgniter中的表單後未設置參數
function myfunction() {
$id = $this->uri->segment(4);
echo $id; //yes, print the value
$data_user = $this->admin_model->query_data_user($id);
$direccion = $data_user[0]->address;
$phone = $data_user[0]->phone;
$this->data['address'] = array(
'name' => 'address',
'id' => 'address',
'value' => $address,
'class' => 'input',
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'value' => $phone,
'class' => 'input',
);
echo $id; //yes, print the value
$this->form_validation->set_rules('address', 'Address', 'xss_clean|max_length[100]');
$this->form_validation->set_rules('phone', 'Phone', 'required|xss_clean|max_length[20]|is_natural_no_zero');
if ($this->form_validation->run() == true) {
echo $id; //here NOT PRINT $id
$data = array(
'address' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
);
$id = $this->uri->segment(4);
echo $id; //here not print the value $id
$this->ion_auth->update_user($id, $data);
$this->load->view('includes/template_mensajes', $data);
}
$this->load->view('users/update_user', $this->data);
}
價值$id
時,它驗證了我的形式,什麼是我的錯誤是不承認?
您是否嘗試使變量$ id爲全局? –