Ich erhalte eine Warnung in meiner Modelldatei in coderigniter sagen Ungültige Argument für foreach() geliefert, wenn ich versuche, meine Where-Bedingung zu bearbeiten.Ungültiges Argument für foreach() mit mpdf im Codezeichen
Eigentlich möchte ich Datensätze nach Fremdschlüssel laden.
Wenn ich diese Codezeile, $this->db->where('project.id',$id);
im Modell hinzufügen, erhalte ich den obigen Fehler.
Controller-Datei
<?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");
}
}
?>
Modelldatei
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;
}
}
View File
<?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 Tisch
ID | Rate | Einheit | project_id
Projekttabelle
id | Standort | client_id
Zu Ihrer Information, ich benutze auch MPDF-Bibliothek und ich lade es in meinem Controller.
Jede Hilfe wird sehr geschätzt werden?
Danke
Sie haben $ id = $ this-> uri-> segment (3) verwendet. Können Sie uns bitte die URL-Struktur mitteilen und haben Sie auch überprüft, ob Sie einen $ id-Wert erhalten? –
site_url ('createpdf/pdf /'.$ row-> id) – ashik
Und was ist mit der Sekunde, in der Sie den Wert von $ id bekommen? Debuggen Sie es. Als Rajkumar R "Wenn das Modell null zurückgibt, wird das ungültige Argument angezeigt". Also überprüfen Sie, ob es den Wert von nicht –