我正在使用html2pdf(dompdf库),使用数据库中的数据创建PDF发票。
生成的pdf完全符合所有格式化css。
生成的pdf没有显示数据库发票的结果,在视图中我放了一个" else"声明,看它是否真的发布了一些东西。它打印出空行。
数据库中的数据就在那里。
我哪里错了?
抱歉英语不好。 谢谢。
我的控制器:
public function index()
{
//Load the library
$this->load->library('html2pdf');
$this->load->model('model_fatture2');
//Set folder to save PDF to
$this->html2pdf->folder('./assets/pdfs/');
// change name file
$nome_file = "pippo";
//Set the filename to save/download as
$this->html2pdf->filename($nome_file.'.pdf');
//Set the paper defaults
$this->html2pdf->paper('a4', 'portrait');
$data['result_fatture'] = $this->model_fatture2->getFattureUtente();
// test view
$data = array(
'title' => 'PDF Created',
'message' => 'Hello World!'
);
//Load html view
$this->html2pdf->html($this->load->view('pdf', $data, true));
if($this->html2pdf->create('download')) {
//PDF was successfully saved or downloaded
echo 'PDF saved';
}
//$this->output->enable_profiler(TRUE);
}
我的模特:
function getFattureUtente() {
$userId = $this->session->userdata('id');
$ProgettoId = $this->session->userdata('id_progetto');
$data = array();
$this->db->select('*');
$this->db->from('fatture');
$this->db->join('users', 'fatture.id_progetto = users.id_progetto');
$this->db->where('id_user',$userId);
$this->db->where('fatture.id_progetto', $ProgettoId);
$query = $this->db->get();
if($query->num_rows() > 0){
foreach ($query->result_array() as $row) {
$data[] = $row;
}
$query->result();
return $data;
}
}
我的观点
<?php if (!empty($result_fatture)): ?>
<?php foreach ($result_fatture as $row): ?>
<?php if ($this->session->userdata('id') === $row['id']): ?>
<table height="20" border="0" cellpadding="0" cellspacing="0" class="table_riga">
<tr>
<td class="col-dx"><?=$row['id_fatture']?></td>
<td class="col-dx"><?=$row['id_user']?></td>
<td class="col-dx"><?=$row['id_progetto']?></td>
<td class="row-bottom"><?=$row['n_progetto']?></td>
<td class="col-sx"><?=$row['data_emissione']?></td>
<td class="col-sx"><?=$row['n_fattura']?></td>
<td class="col-sx"><?=$row['prezzo']?></td>
</tr>
</table>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php echo "rows empty"; ?>
<?php endif; ?>
答案 0 :(得分:0)
解决了!我没有宣布会议,所以会议结束 - &gt; userdata(&#39; id&#39;)=== $ row [&#39; id&#39;]):?&gt;返回错误。如果它可以帮助某人。感谢