Organization of the code in the controller codeigniter

0

I am using the HTML Table Class and the table settings are defined through an array according to codeigniter's own documentation link

I've created a method that only returns this array of configuration to improve the visualization of the code.

I would like to know if this is the best approach or is there some other way that will make 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;
}
    
asked by anonymous 04.11.2016 / 17:00

1 answer

1

Rafael, if the configuration values are not changed, you'd better use a class variable or a configuration file in application / config , instead of having a method to return those values.

    
08.11.2016 / 20:17