如何使用Codeigniter通过表单操作在控制器中传递ID [英] how to pass id in controller from form action using codeigniter
本文介绍了如何使用Codeigniter通过表单操作在控制器中传递ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我是Codeigniter的新手,我有这样的表单
hey guys i am new in codeigniter,i have a form like this
<form class="addinvestmentform" action="<?php echo base_url();?>index.php/ctl_dbcont/input_investment/$id" name="application" method="post" >
//some code
</form>
我有一个控制器方法
function input_investment($id)
{
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('mod_user');
$this->mod_user->insertinvestment($id);
}
我想从表单操作到控制器方法获取$ id我该怎么办那。 。请帮助我 。 。
i want to get $id from form action to controller methode how can i do that . . pls help me . .
推荐答案
最好在隐藏字段中传递值
better to pass the value in the hidden field
<form class="addinvestmentform" action="<?php echo base_url();?>index.php/ctl_dbcont/input_investment" name="application" method="post" >
<input type="hidden" name="my_id" value="<?php echo $id; ?>"/>
</form>
在您的ci函数中
function input_investment() {
$id = $this->input->post('my_id');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('mod_user');
$this->mod_user->insertinvestment($id);
}
或者如果您愿意(测试)
or if you want (A test)
//示例视图
<?php $id = 1; ?>
<form action="<?php echo base_url('my_class/my_method/' . $id); ?>" method="post" >
<input type="submit" />
</form>
//控制器
class My_class extends CI_Controller {
public function index() {
$this->load->view('my_class');
}
public function my_method($id) {
echo $id; // outputs 1
}
}
这篇关于如何使用Codeigniter通过表单操作在控制器中传递ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文