私のモデルファイルで警告が発生しました。私のwhere条件を編集しようとしたときにforeach()の引数が無効です。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++;
}
?>
BOQテーブル
id |レート|ユニット|プロジェクトID
プロジェクトテーブル
id |ロケーション| client_id
あなたの情報については、私もMPDFライブラリを使用しています。コントローラにロードしています。
ご協力いただきありがとうございます。
ありがとうございました
あなたは$ id = $ this-> uri-> segment(3)を使用してURL構造を知っていて、あなたが$ id値を取得しているかどうかを確認できますか? –
site_url( 'createpdf/pdf /'.$ row-> id) – ashik
そして、2番めのものは$ idの値を得ていますか?それをデバッグします。 Rajkumar Rのように "モデルがnullを返した場合、エラー無効な引数が表示されます"という意味です。それでは、それが –