Good morning guys, I'm developing CRM
using the CodeIgniter
framework and I'm not able to export some CRUD
lists using the MPDF
library.
I'm trying to use the ob_start()
function as indicated in the library manual itself, but when exporting, I get the following error in return:
Below,thecodesused:
view:
<divclass="col-sm-2">
<a href="http://localhost/sistema/clientes/inserir" class="btn btn- primary pull-right h2">Novo Cliente</a>
</div>
<div id="list" class="row">
<div class="table-responsive col-md-12">
<table class="table table-striped" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>ID</th>
<th>Empresa</th>
<th>Contato</th>
<th>Telefone</th>
<th>Email</th>
<th>Cidade</th>
<th class="actions">Ações</th>
</tr>
</thead>
<tbody>
<?php foreach ( $clientes as $cliente ) {?>
<tr>
<td><?php echo $cliente->ccod; ?></td>
<td><?php echo $cliente->cnome; ?></td>
<td><?php echo $cliente->contato; ?></td>
<td><?php echo $cliente->telefone; ?></td>
<td><?php echo $cliente->email; ?></td>
<td><?php echo $cliente->cidade; ?> </td>
<td class="actions">
<a title="history" class="btn btn-success btn-xs" href="<?php echo base_url() . 'comments/history/' . $cliente->ccod; ?>">Historico</a>
<a title="orçamentos" class="btn btn-default btn-xs" href="<?php echo base_url() . 'orcamentos/history/' . $cliente->ccod; ?>">Orçamentos</a>
<a title="Editar" class="btn btn-warning btn-xs" href="<?php echo base_url() . 'clientes/editar/' . $cliente->ccod; ?>"> Editar</a>
<a title="Deletar" class="btn btn-danger btn-xs" href="<?php echo base_url() . 'clientes/deletar/' . $cliente->ccod; ?>" onclick="return confirm('Confirma a exclus�o deste registro?')">Deletar</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-sm-12">
<a href="http://localhost/sistema/clientes/exports" class="btn btn-default btn-xs pull-right h2">Exportar</a>
</div>
I'm putting the ob_start()
logo function at the beginning of the view containing the HTML
of the page.
Controller:
public function exports(){
$html= ob_get_contents();
ob_end_clean();
//this the the PDF filename that user will get to download
$pdfFilePath = "relatorio de clientes.pdf";
//load mPDF library
$this->load->library('m_pdf');
//actually, you can pass mPDF parameter on this load() function
$pdf = $this->m_pdf->load();
//generate the PDF!
$pdf->WriteHTML($html);
//offer it to user via browser download! (The PDF won't be saved on your server HDD)
$pdf->Output($pdfFilePath, "D");
}
In addition, I did not change anything in the files of the library, and complementing, follows a print from the screen where I'm trying to export the list, note that what I want to do is just print the list, the layout part and the menu do not.
I'm a beginner with PHP
, I'm not sure if I'm putting the function in the correct location for my code.