我正在尝试从视图发送id到CodeIgniter中的控制器.我的要求是根据按钮id切换功能.这是我的 HTML代码.
查看HTML
<?php echo form_open_multipart('upload_control/switch_load','id="bt_addImage"');?>
<input id= "bt_addImage" type="submit" value="Add Image" /> <br>
<?php echo form_open_multipart('upload_control/switch_load','id="bt_chooseImage"');?>
<input type="submit" id="bt_chooseImage" value="Submit"/><br>
Upload_control.php代码
public function switch_load($id)
{
if($id == "bt_addImage")
{
do_loadcategories();
}
else
{
do_upload();
}
}
public function do_loadcategories()
{
//code list categories
}
public function do_upload()
{
//code to upload
}
这是正确的吗?
要么
还有其他办法吗?
帮我解决问题.
最佳答案 在视图中
$hiddenFields = array('id' => 'bt_addImage'); # add Hidden parameters like this
echo form_open_multipart('upload_control/switch_load', '', $hiddenFields);
在控制器中
public function switch_load()
{
$id = $this->input->post('id');
if($id == "bt_addImage")
{
do_loadcategories();
}
else
{
do_upload();
}
}
看起来像这样
<form method="post" accept-charset="utf-8" action="http:/example.com/index.php/upload_control/switch_load">
<input type="hidden" name="id" value="bt_addImage" /> # hidden filed.
Codeigniter Form Helper