Arrays Codeigniter通过post信息和post信息的数据库结果一起查看
我有一个表格收集Arrays Codeigniter通过post信息和post信息的数据库结果一起查看,arrays,codeigniter,activerecord,Arrays,Codeigniter,Activerecord,我有一个表格收集客户名称、期间和计量单位[buom] 然后我将此信息传递给我的控制器,控制器将post数据放入一个数组并将其传递给视图 该控制器目前100%工作 function new_blank_order_lines() { if($this->input->post()){ $data = array( 'customer' =>$this->input->post('customer'), 'period' =>$
客户名称
、期间
和计量单位
[buom]
然后我将此信息传递给我的控制器,控制器将post数据放入一个数组并将其传递给视图
该控制器目前100%工作
function new_blank_order_lines()
{
if($this->input->post()){
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom')
);
$this->session->set_userdata($data);
$this->Sales_model->get_creditlimit($this->input->post('customer'));
}
$this->load->view('sales/new_blank_order_lines',$this->session->all_userdata());
}
else {
redirect('/sales/permError');
}
}
我要做的是使用customer post值查询客户信用额度
和信用余额
,并将其传递给我的视图,以便在下一个表单中使用
所以我的模型是:
function get_creditlimit($customer)
{
$this->db->select('creditlimit','creditbalance');
$this->db->from('Customers');
$this->db->where('Customername',$customer);
$q = $this->db->get();
if($q->num_rows() > 0)
{
return $q->result();
}
}
因此,在我的控制器中,我使用以下命令调用模型函数:
$this->Sales\u model->get\u creditlimit($this->input->post('customer')代码>
这里我将customer
post值传递给模型,以获取正确的信用额度?这是正确的吗
我的问题是如何将post信息数组传递给视图,将信用额度信息传递给视图
我是否需要将模型结果添加到数组并传递单个数组?如果是这样,我该怎么做
一如既往地感谢您,只需将其添加到$data数组中即可:
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom'),
'creditLimit' => $this->Sales_model->get_creditlimit($this->input->post('customer'))
);
您的新的\u blank\u order\u line()
函数中似乎有太多的}
。您可能需要删除此行上方的}
:$this->load->view('sales/new\u blank\u order\u line',$this->session->all\u userdata())代码>感谢Mudshark,除了echo$creditLimit,php输出为数组时,工作正常。。。我需要循环这个吗?如果您总是从查询中收到一行,我会执行return$q->row_array()
在模型的方法中,然后可以使用$creditLimit['creditLimit']访问视图中的数据代码>和$creditLimit['creditbalance']
.Hi Mudshark,按照上面的建议做了,但PHP错误是stdClass类的对象无法转换为字符串。打印显示数组([0]=>stdClass对象([creditlimit]=>300000))
creditbalance没有数组值。有什么想法吗?thanksMy模型语法不正确。应该是$this->db->select('creditlimit,currentbalance')代码>