Alternative to the Codigniter table component

Asked

Viewed 47 times

0

I am developing the following screen using Codeigniter:

inserir a descrição da imagem aqui

My difficulty is in leaving the code in an elegant way, without the use of the table library (I think it is not the most suitable for what I am doing) and without large data manipulations in the view, I would like some suggestions on how to perform this activity.

View.php

<div id="container">
    <?php include 'menu.php';?>
    <center>
        <h1>Tarefas</h1>
    </center>
    <div id="body">
    <center>
        <?php echo form_open('tarefa/detalhes'); ?>



        <?php  $this->load->library('table');
            echo $this->table->generate();  


          echo form_close(); ?>
    <center>
    </div>
    <p class="footer">
        PGM renderizado em <strong>{elapsed_time}</strong> segundos
    </p>
</div>

Controler.php

public function index()
{
    $this->load->helper('form');
    $this->load->library('table');
    $this->load->helper('form');

    $query = $this->tarefa_model->busca_tarefa_ordenado_por_estado();

    $head = array();
    $tarefanterior ="";

    foreach ($query->result() as $row)
    {

        $data['equipeTarefas'][] = array(
                'Sequencia' => $row->sequencia,
                'Nome' => $row->nome,
                'id' => $row->id ==""?"":"#".$row->id,
                'Titulo' => $row->titulo);

        if(!in_array($row->nome,$head)){
            array_push($head,$row->nome );
        }

        $tarefa = '<figure id="containerimage">
            <input type="image"  src="'.base_url().'postit.jpeg" id="centro" name="tarefa" value="'.$row->id.'"><figcaption>#'.$row->id." ".$row->titulo.'</figcaption>
        </figure>';


        $this->table->add_row($row->sequencia== 1?"$tarefa":"", $row->sequencia== 2?$tarefa:"",$row->sequencia== 3?$tarefa:"");

    }


    $this->table->set_heading($head);

    $this->load->view('tarefa_view',$data);

}

1 answer

1

You can create your own library, including extending the native CI, just create a file application/libraries/MY_Table.php :

defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Table extends CI_Table {

    public function __construct() {
        parent::__construct();
    }
// defina ou sobrescreva os metodos ...

Otherwise, you could create a Helper, in a similar process.

Remembering that the MY_ prefix is set in the file application/config.php, in the parameter $config['subclass_prefix'] = 'MY_'; I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.