【发布时间】:2016-07-11 16:42:11
【问题描述】:
当我尝试在 Codeigniter 中使用 DOMPDF 从表中打印数据时出现一些错误。看我的照片click here
遇到 PHP 错误
严重性:通知
消息:试图获取非对象的属性
文件名:views/print-pasien.php
行号:57
以及我的 print-pasien 视图中的其他行号。
嗯,这是我的以下代码:
控制器
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));
}
型号
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;
}
查看
<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:我的数据库表中没有保存任何'umur'字段的数据,我只是在我的模型上使用SQL语句调用它。
【问题讨论】:
-
我敢打赌,在发布此错误之前,您甚至从未尝试过 Google 那个错误。我说的对吗?
-
所以
$data不是一个对象。你需要做var_dump($data)看看它是什么。也许它是一个数组,而不是一个对象。 -
我试过了,我也尝试在 stackoverflow 上搜索,但我就是不明白,抱歉我还是使用 Codeigniter @AlonEitan 的新手
标签: php codeigniter