2
Good morning guys, I’m developing a CRM
using the framework CodeIgniter
and I’m not able to export some lists CRUD
using the library MPDF
.
I’m trying to use the function ob_start()
as indicated in the library’s own manual, but when exporting, I get the following error as return:
Below are the codes used:
view:
<div class="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 setting the function ob_start()
at the beginning of the view containing the HTML
of the page.
Controler:
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");
}
Also, I didn’t change anything in the library files, and in addition, follow a screenshot of where I am trying to export the list, note that what I intend to do is just print the list, the layout part and menu.
I’m beginner with PHP
, do not know if I am putting the function in the correct location of my code.
Show the
VIEW
complete, please.– ShutUpMagda
Organize: You won’t be able to do the same
view
generate both the list and the pdf. Not the way you want it. Right, in this case, it is one method to generate the list, another to generate the pdf report from the list (are two things). A controller generates the list based on filters, right? Then the button Export can generate the report based on these same filters. It is much more complex than it seems...– ShutUpMagda
I believe I understood what you meant, yes in my controller I am using a method to create the list of items, and a method to export, but I tried to take advantage of the same view actually, I will switch to the way you indicated and put the result. thank you
– Felipe Miranda De Lima