How to pass a value of a variable from view to controller in codeigniter

馋奶兔 提交于 2020-01-15 04:26:06

问题


using form post method i need to pass a value of numIDto a controller

for example assigning a value to numID inside view,

$numID= 25;

i need to use value of numID in a controller and assign that to temp variable. so i use following line of code,

$temp= $_POST[numID];

but its unable to get the exact value. Please help me on this. If have any other alternate way please let me know.


回答1:


Here is an example of sending info from view to the controller:

View:

<?php echo form_open('invoice'); ?>
<?php echo validation_errors(); ?>
<?php echo form_input('order_num', $this->input->post('order_num')); ?>
<?php echo form_submit('submit','submit'); ?>
<?php echo form_close(); ?>

Controller:

public function invoice()
{
$order = $this->input->post('order_num');
$this->General_Model->get_customer_order($order);
}

Model:

function get_customer_order($order)
{
 . . .
$this->db->where('client_orders.id', $order);
$result = $this->db->get('client_orders');
. . .
}

Note we are using the input name and id as = "order_num" Then we ask the controller to find it as $this->input->post('order_num');



来源:https://stackoverflow.com/questions/33675595/how-to-pass-a-value-of-a-variable-from-view-to-controller-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!