我在codeigniter中的模型文件中獲得警告爲foreach提供了無效參數()當我試圖編輯我的where條件時。在codeigniter中使用mpdf提供的foreach()的無效參數
其實我想加載記錄根據外鍵。
當我在模型中添加這行代碼$this->db->where('project.id',$id);
時,出現上述錯誤。
控制器的文件
<?php
class Createpdf extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('m_pdf');
$this->load->model('boq_pdf_model');
$this->load->model('project_list_model');
}
function pdf()
{
$id= $this->uri->segment(3) ;
$data['projects'] = $this->project_list_model->show_projects();
$data['boq'] = $this->boq_pdf_model->get_boq($id);
$this->load->view('boq/boq_report',$data);
}
public function topdf(){
//this data will be passed on to the view
$data['the_content']='RCJ Constructions';
//load the view, pass the variable and do not show it but "save" the output into $html variable
$html=$this->load->view('boq/boq_report', $data, true);
//this the the PDF filename that user will get to download
$pdfFilePath = "boq_report.pdf";
//load mPDF library
//$this->load->library('m_pdf');
//actually, you can pass mPDF parameter on this load() function
$pdf = $this->m_pdf->load();
$id= $this->uri->segment(3) ;
$data['projects'] = $this->project_list_model->show_projects();
$data['boq'] = $this->boq_pdf_model->get_boq($id);
$html = $this->load->view('boq/boq_report', $data, true);
//generate the PDF!
$pdf->WriteHTML($html);
//offer it to user via browser download! (The PDF won't be saved on your server HDD)
$pdf->Output($pdfFilePath, "D");
}
}
?>
模型文件
function get_boq($id){
$this->db->select('*');
$this->db->from('boq');
$this->db->join('project', 'project.id = boq.project_id');
$this->db->where('project.id',$id);
$this->db->order_by('item_no','ASC');
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
}
}
查看文件
<?php
foreach ($boq as $rows) {
<tr>
<td><?php echo $rows['unit'] ?></td>
<td><?php echo $rows['rate']?></td>
<td><?php echo $rows['laboure_hrs'] ?></td>
<td><?php echo $rows['laboure_cost'] ?></td>
</tr>
<?php
//$i++;
}
?>
工程量清單表
ID |率|單位| project_id
項目表
id |位置| client_id
爲了您的信息,我使用MPDF庫以及我加載它在我的控制器。
任何幫助將被高度讚賞?
謝謝
您已使用$ id = $ this-> uri-> segment(3)您能否讓我們知道網址結構,並且是否檢查了您是否獲得了$ id值? –
site_url('createpdf/pdf /'.$ row-> id) – ashik
第二種方法是獲取$ id的值。調試它。作爲Rajkumar R「如果模型返回null意味着它將顯示錯誤無效參數」。所以檢查它是否通過價值不是 –