【问题标题】:Codeigniter pass post information to view along with database result of the post informationCodeigniter 将帖子信息与帖子信息的数据库结果一起查看
【发布时间】:2013-04-05 08:57:30
【问题描述】:

我有一个收集CustomerNamePeriodUnitOfMeasure[buom] 的表单。

然后我将此信息传递给我的控制器,该控制器将发布数据放入一个数组并将其传递给视图。

此控制器目前 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');
    }
  }

我想做的是使用客户发布值查询客户credit limit AND credit balance,并将其传递给我的视图以在下一个表单中使用。

所以我的模型是:

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_model->get_creditlimit($this->input->post('customer')); 在这里我将customer 后值传递给模型以获取正确的信用额度?这是正确的吗?

我的问题是如何将帖子信息数组传递给视图并将信用额度信息传递给视图。

是否需要将模型结果添加到数组并传递单个数组?如果是这样,我该怎么做?

一如既往的感谢,

【问题讨论】:

  • 您的new_blank_order_lines() 函数中似乎有太多}。您可能希望删除此行上方的 }$this->load->view('sales/new_blank_order_lines',$this->session->all_userdata());

标签: arrays codeigniter activerecord


【解决方案1】:

只需将其添加到 $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'))
);

【讨论】:

  • 感谢 Mudshark,除了 echo $creditLimit,php 输出为数组外,工作完美...我需要循环遍历吗?
  • 如果您总是要从查询中收到一行,我会在您的模型方法中使用return $q->row_array();,然后您可以使用$creditLimit['creditlimit'];和@ 访问视图中的数据987654324@.
  • 嗨 Mudshark,按照你上面的建议做了,但是 PHP 错误是 Object of class stdClass could not be converted to string。 print_r 显示 Array ( [0] => stdClass Object ( [creditlimit] => 300000 ) ) 没有 creditbalance 的数组值。有任何想法吗?谢谢
  • 我的模型语法不正确。应该是$this->db->select('creditlimit,currentbalance');
猜你喜欢
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
  • 1970-01-01
相关资源
最近更新 更多