I got some error when I am trying to print my data from my table using DOMPDF in Codeigniter. See my picture click here
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/print-pasien.php
Line Number: 57
and other lines number on my print-pasien views as well.
Well, this is my following code :
Controller
public function cetak_pasien(){
$data['pasien'] = $this->a_model->view();
$this->load->view('print-pasien', $data);
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("print-pasien" . ".pdf", array ('Attachment' => 0));
}
Model
public function view(){
$query = $this->db->query("SELECT kode_pasien,nama_pasien, email_pasien, alamat_pasien, tanggal_lahir,TIMESTAMPDIFF(YEAR,tanggal_lahir,CURDATE()) AS umur, jenis_kelamin, no_telp FROM tb_pasien");
return $query;
}
View
<table width="100%">
<tr>
<th>No</th>
<th>Kode Pasien</th>
<th>Nama Pasien</th>
<th>Email Pasien</th>
<th>Alamat Pasien</th>
<th>Tanggal Lahir</th>
<th>Umur</th>
<th>JK</th>
<th>No. Telp</th>
</tr>
<?php
if( ! empty($pasien)){
$no = 1;
foreach($pasien as $data){
echo "<tr>";
echo "<td>".$no."</td>";
echo "<td>".$data->kode_pasien."</td>"; //here my problem
echo "<td>".$data->nama_pasien."</td>"; //here my problem
echo "<td>".$data->email_pasien."</td>"; //here my problem
echo "<td>".$data->alamat_pasien."</td>"; //here my problem
echo "<td>".$data->tanggal_lahir."</td>"; //here my problem
echo "<td>".$data->umur."</td>"; //here my problem
echo "<td>".$data->jenis_kelamin."</td>"; //here my problem
echo "<td>".$data->no_telp."</td>"; //here my problem
echo "</tr>";
$no++;
}
}
?>
</table>
PS: I didnt hold any data of 'umur' field on my database table, I only call it by using SQL statement on my model.