我通过URL传递变量$id
,并在表单表单更新中加载数据,但是当我要验证表单时,无法识别值$id
。
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
是不被识别的,当它验证我的形式,我的错误是什么?
您要将表单提交到哪里?您确定在表单的action属性上传递URI中的ID吗?
例如,你的表单打开标签应该看起来像
<form action="/admin/myfunction/<?= $id ?>">
或使用代码编写器帮助器
echo form_open('admin/myfunction/' . $id);
如果我没有弄错,我的函数是一个动作在你的控制器称为…比如mycontroller。然后你应该发送这个url: http://localhost/mycontroller/myfunction/1234
并将您的操作更新为接受ID参数$ ID。CodeIgniter会处理剩下的。
function myfunction($id) {
...
}
您需要将$id变量传递到表单中作为隐藏字段,并将其作为POST值返回
将我的id添加到URL的末尾,例如www.whsconcepts.com/?id=100
,我把它唤回我的形态。例如:
form_open('the url I want' . $_Get ['id'])