0
데이터베이스의 데이터로 PDF 인보이스를 작성하기 위해 html2pdf (dompdf 라이브러리)를 사용하고 있습니다.해결되었습니다! codeigniter - 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; ?>
해결되었습니다! 나는이 세션을 선언하지 않았다. PHP는// if ($ this-> session-> userdata ('id') === $ row [ 'id']) :?> RETURN FALSE. 누군가를 도울 수 있다면. 감사합니다. – user3311699