我尝试使用表单助手CI创建更新表单。everything在Form_input上工作。但是,当id在form_hidden上时,它会返回NULL。这是脚本查看
$hidden = array('name'=>'id_hidden','value'=>$datacompany[0]->id);
echo form_hidden($hidden); //I have edited
控制器上
function edit_company()
{
if(isset($_POST['EDIT']))
{
print_r($_POST);//return All value
$isi = array(
'id' =>$this->input->post('id_hidden'),//return null
'nip' =>$this->input->post('nip'),//return value
'nama' =>$this->input->post('nama'), //return value
'golongan' =>$this->input->post('golongan') //return value
);
echo $isi['id']; //the result id is null
}//end if
}//end Function
我需要在模型上使用这个Id。我该怎么解决?如何从form_hidden获取ID?
我非常感谢你的回答
感谢
虽然使用我的第一条注释可以让你在3秒内调试它,但答案是:)
您使用表单的方式不对。
form_hidden中的一个数组变成这个(来自文档)
$data = array(
'name' => 'John Doe',
'email' => 'john@example.com',
'url' => 'http://example.com'
);
echo form_hidden($data);
//将产生:
<input type="hidden" name="name" value="John Doe" />
<input type="hidden" name="email" value="john@example.com" />
<input type="hidden" name="url" value="http://example.com" />
正如您所看到的,数组的"键"会转向字段的名称。该值是数组的"value"。因此,在您的示例中,您将生成两个隐藏字段。
<input type="hidden" name="name" value="id_hidden">
<input type="hidden" name="value" value="$datacompany[0]->id">
您需要像这样在CI:中定义一个隐藏字段
$hidden = array('id_hidden',$datacompany[0]->id); // a name and value pair for a single instance.
echo form_hidden($hidden);
$hidden = array('id_hidden' => $datacompany[0]->id);
echo form_hidden($hidden);
我认为这将满足你的需要。或者如果你想要其他属性。。。试试这个。。
$data = array(
'name' => 'username',
'id' => 'username',
'value' => 'johndoe',
'maxlength' => '100',
'type' => 'hidden',
'size' => '50',
'style' => 'width:50%',
);
echo form_input($data);
取决于你的需要。