How to pass variable between views?

0

My problem is this. The dashboard of my project has an input where the user enters the process number and clicks to search, as per the code below:

  <form class="navbar-form navbar-left" role="search" action="<?= base_url() ?>processo/pesquisar" method="post">
        <div class="form-group">
            <input type="text" style="width: 250px;" name="pesquisar" class="form-control" placeholder="Digite o número do processo" required>
            <button type="submit" class="btn btn-default btn-md"> CONSULTAR</button>
        </div>            
    </form>

When I click Search, I call the Processor search method of the Process, as below, which calls the get_processos_like method of the model, Process_model:

public function pesquisar() {
    $this->load->model('Processo_model', 'processo');
    $dados['processo'] = $this->processo->get_processos_like();
    if (!$this->processo->get_processos_like()) {
        $data["msg"] = "Processo não encontrado.";
        $this->load->view('includes/msg_erro', $data);
    } else {
        $this->load->view('/listar/listar_processo_adv', $dados);
    }         
}

 #Método get_processos_like do Model:

 function get_processos_like() {
    $termo = $this->input->post('pesquisar');
    $this->db->select('*');
    $this->db->where('nprocesso', $termo);
    return $this->db->get('processo')->result();
}

This method returns the data of the searched process to view list_processos_adv.php, which displays all the process information and has a link calling another view, as below:

    <div class="row">     
                <div align="center">
                    <button type="button" title="Detalhes" onclick="window.location.href = '<?= base_url('processo/custas')?>'" class="btn btn-primary>INFORMAÇÕES DE CUSTAS</button>
                </div>
    </div>  
                    
asked by anonymous 22.05.2018 / 01:05

1 answer

2

You can pass the value via GET in the URL to the custas method. I suggest using <a> instead of <button> . You can use class="btn btn-primary" in <a> as well. It would look like this:

<div class="row">     
    <div align="center">
        <a href="<?=base_url('processo/custas/'.$codProcesso)?>" target="_blank" class="btn btn-primary">INFORMAÇÕES DE CUSTA</a>
    </div>
</div>

Remembering that in Codeigniter variables that are passed via GET can be tracked from the parameters of the controller method. In your case. the custas method of the processo driver should look like this: public function custas($codProcesso) {...} and within this method you will get the details of the process in the database and send it to the details page that you develop. ($ this- > load- > view (...))

I hope I have helped.

    
23.05.2018 / 02:19