0
I am using the HTML Table Class and the table settings are defined through an array as documentation of the codeigniter itself http://www.codeigniter.com/user_guide/libraries/table.html?highlight=table#Changing-the-look-of-your-table
I created a method that only returns this configuration array to enhance the code view.
I would like to know if this is the best approach or is there any other way that leaves the code more organized without the need to create this method?
function gera_arquivo()
{
$this->table->set_template($this->define_template_table());
$this->table->set_heading($this->define_cabecalho_tabela());
$result = $this->model_acionamento->consulta_extracao($this->define_where_extracao());
foreach ($result->result_array() as $row)
{
$dados_linha = [
$row['nr_acionamento'],
$row['dt_alarme'],
$row['dt_abertura'],
$row['dt_aceite'],
$row['ds_status'],
utf8_decode($row['setor_responsavel']),
utf8_decode($row['ds_tipo']),
utf8_decode($row['nm_usuario_abertura']),
utf8_decode($row['nm_usuario_aceite']),
utf8_decode($row['nm_usuario_finaliza']),
$row['cd_operadora'],
$row['cd_node'],
$row['nr_oc'],
$row['nr_outage'],
$row['cod_baixa'],
utf8_decode($row['ds_baixa']),
$row['fc_confirmada_falta_energia'],
$row['nr_protocolo'],
$row['nm_concessionaria'],
$row['dt_previsao'],
];
$this->table->add_row($dados_linha);
}
$arquivo = 'extracao_monitoracao.xls';
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: application/x-msexcel');
header("Content-Disposition: attachment; filename=\"{$arquivo}\"");
echo $this->table->generate();
}
function define_template_table()
{
$template = [
'table_open' => '<table border=1>',
'thead_open' => '<thead>',
'thead_close' => '</thead>',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',
'tbody_open' => '<tbody>',
'tbody_close' => '</tbody>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
];
return $template;
}
I had trouble implementing a variable file in config, but I will try again. Thank you Jonathan
– Rafael Simionato Hayashi