如何在循环内使用this-> data []从控制器传递变量到php CI中查看

时间:2016-11-21 04:50:21

标签: php codeigniter

for ($i = 0; $i < $count; $i++) {
  $this->data["schedule_count"] = $count;
  $this->data["user_travels" . $i] = $this->travel_order_model->get_travel_schedule($this->data["user_dates"]{$i}->id);
}

错误:

  

遇到PHP错误

严重性:注意

  

消息:未定义的变量:user_travels

     

文件名:travel_order / travel_order_report_summary.php

     

行号:212

遇到PHP错误

严重性:警告

  

消息:为foreach()提供的参数无效

     

文件名:travel_order / travel_order_report_summary.php

     

行号:213

2 个答案:

答案 0 :(得分:1)

for ($i = 0; $i < $count; $i++) {
  $this->data["schedule_count"] = $count;
  $this->data["user_travels"][$i] = $this->travel_order_model->get_travel_schedule($this->data["user_dates"][$i]->id);
}
$this->load->view('your_view_file', $data);

您的查看文件,您可以通过这种方式打印数据,

foreach($user_travels as $travelData){
    print_r($travelData);
}

答案 1 :(得分:1)

for ($i = 0; $i < $count; $i++) {
  $this->data["schedule_count"] = $count;
  // pass Id 
  $this->data["user_travels"][$i] = $this->travel_order_model->get_travel_schedule($this->data["user_dates"][$i]->getId());
}