如何将变量的值从视图传递到Codeigniter中的控制器 [英] How to pass a value of a variable from view to controller in codeigniter

查看:38
本文介绍了如何将变量的值从视图传递到Codeigniter中的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用表单发布方法,我需要将 numID 的值传递给控制器​​

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

例如,在视图内为 numID 分配一个值,

for example assigning a value to numID inside view,

$numID= 25;

我需要在控制器中使用 numID 的值,并将其分配给 temp 变量.所以我使用以下代码行

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.

推荐答案

以下是从视图向控制器发送信息的示例:

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

查看:

<?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(); ?>

控制器:

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

型号:

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

请注意,我们使用的输入名称和ID为 ="order_num" 然后,我们要求控制器将其找到为 $ this-> input-> post('order_num');

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');

这篇关于如何将变量的值从视图传递到Codeigniter中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆