1
Hello,
I am trying to generate a report using Dompdf but am encountering the following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Relatorio::$dompdf
Filename: controllers/Relatorio.php
Line Number: 24
Backtrace:
File: C:\xampp\htdocs\ci_ads\application\controllers\Relatorio.php
Line: 24
Function: _error_handler
File: C:\xampp\htdocs\ci_ads\index.php
Line: 315
Function: require_once
My view:
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
</head>
<body>
<style>
table {
width: 100%;
height: 100%;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
table thead tr th td {
border: 1px solid black;
}
table thead tr th {
background-color: #bac6cb;
font-size: 17px;
}
table tbody tr td {
background-color: #9ba7ac;
font-size: 14px;
}
</style>
<div id="flex-box">
<table>
<thead>
<tr>
<td style="text-align: center" colspan="2"><h2>Alunos com maior número de locação</h2></td>
</tr>
<tr style="text-align: center">
<th>Nome do aluno</th>
<th>Quantidade de locação</th>
</tr>
</thead>
<tbody>
<?php foreach ($rel as $linha) {
echo '<tr>';
echo "<td style=\"text-align: center\">" . $linha['nome'] . "</td>";
echo "<td style=\"text-align: center\">" . $linha['count'] . "</td>";
echo '</tr>';
} ?>
</tbody>
</table>
<p>
Relatório de alunos que mais locaram E-Book ®
</p>
</div>
</body>
</html>
My Controller
class Report extends Ci_controller {
function __construct() {
parent::__construct();
$this->load->model('relatorio_model');
}
public function index() {
$this->load->view('template/header');
$this->load->view('relatorio/index');
$this->load->view('template/footer');
}
public function geraRelatorio() {
$dados = $this->input->post();
if ($dados['tipo_relatorio'] == 'REL_LIVRO_MAIS_LOCADO') {
$data['rel'] = $this->relatorio_model->queryAlunosMaisLocaram();
$this->load->library('pdf');
$html = $this->load->view('relatorio/livros_mais_locados', $dados, true);
$this->dompdf->load_html($html);
$this->dompdf->set_paper("A4", "portrait"); // to change page orientation to landscape, change the parameter “portrait” to “landscape”
$this->dompdf->render();
$filename = "mypdf.pdf";
$this->dompdf->stream($filename); // to Download PDF
}
if ($dados['tipo_relatorio'] == 'REL_ALUNOS_MAIS_LOCARAM') {
$data['rel'] = $this->relatorio_model->queryAlunosMaisLocaram();
$this->load->library('pdf');
$html = $this->load->view('relatorio/alunos_mais_locaram', $dados, true);
$this->dompdf->load_html($html);
$this->dompdf->set_paper("A4", "portrait"); // to change page orientation to landscape, change the parameter “portrait” to “landscape”
$this->dompdf->render();
$filename = "mypdf.pdf";
$this->dompdf->stream($filename); // to Download PDF
}
}
}
Would anyone have any suggestions? Thank you
The mPDF library is very complicated and unusual, I strongly recommend the Phpjasper library: https://github.com/geekcom/phpjasper
– geekcom
It means that it works very well up to a certain limit of data, for example: very large reports with several joins, you have to write a lot to generate, and it takes time, although it is very good in small and medium reports, unusual pq you need to write a lot to generate a medium to large report.
– geekcom
Exactly why I wrote as a comment (suggestion or tip) and not as a response ;)
– geekcom
The important thing is that the solution works well for the colleague who asked, I hope that is the case.
– geekcom