Calling an Array of a Public Function in Codeigniter View

0

I have this public function in Controller :

public function faturar() {

    $this->load->library('form_validation');
    $this->data['custom_error'] = '';


    if ($this->form_validation->run('receita') == false) 
    {
        $this->data['custom_error'] = (validation_errors() ? '<div class="form_error">' . validation_errors() . '</div>' : false);
    } 
    else 
    {
        $vencimento = $this->input->post('vencimento');
        $recebimento = $this->input->post('recebimento');

        try {

            $vencimento = explode('/', $vencimento);
            $vencimento = $vencimento[2].'-'.$vencimento[1].'-'.$vencimento[0];

            if($recebimento != null){
                $recebimento = explode('/', $recebimento);
                $recebimento = $recebimento[2].'-'.$recebimento[1].'-'.$recebimento[0];

            }
        } catch (Exception $e) {
           $vencimento = date('Y/m/d'); 
        }

        $data = array(
            'descricao' => set_value('descricao'),
            'valor' => $this->input->post('valor'),
            'clientes_id' => $this->input->post('clientes_id'),
            'data_vencimento' => $vencimento,
            'data_pagamento' => $recebimento,
            'baixado' => $this->input->post('recebido'),
            'cliente_fornecedor' => set_value('cliente'),
            'forma_pgto' => $this->input->post('formaPgto'),
            'tipo' => $this->input->post('tipo')
        );

        if ($this->os_model->add('lancamentos',$data) == TRUE) { 

            $os = $this->input->post('os_id'); 

            $this->db->set('faturado',1);
            $this->db->set('valorTotal',$this->input->post('valor'));
            $this->db->where('idOs', $os);
            $this->db->update('os'); 

            $this->session->set_flashdata('success','OS faturada com sucesso!');
            $json = array('result'=>  true);
            echo json_encode($json);
            die();
        } else {
            $this->session->set_flashdata('error','Ocorreu um erro ao tentar faturar OS.');
            $json = array('result'=>  false);
            echo json_encode($json);
            die();
        }
    }

    $this->session->set_flashdata('error','Ocorreu um erro ao tentar faturar OS.');
    $json = array('result'=>  false);
    echo json_encode($json);

}

And in the View I have this code:

<li>
    <span><h5>Técnico Responsável</h5></span>
    <span><strong>Nome: </strong> <?php echo $result->nome?></span> <br/>
    <span><strong>OS: </strong><?php echo $result->idOs ?></br></span>
    <span><strong>Data Inicial: </strong><?php echo $dataInicial ?></br></span>
    <span><strong>Data Final: </strong><?php echo $dataFinal ?></br></span>
    <span><strong>Data da Impressão desse documento: </strong><?php echo date('d/m/Y'); ?></br></span>
    <span><strong><h4>Status da OS: <?php echo $result->status ?></h4></strong></span>
    <?php  if(faturar(baixado)=1) { echo '<span><strong><h5>Fatura Paga</h5></strong></span>'; } ?>     
</li>

In the last line of the view, where <?php if(faturar(baixado)=1) is written, I want to call the 'downloaded' key from the $ data array and check the database whether the record was downloaded or not.

Is there a way to do this directly in View , without having to create a function in Model , then in Controller and then View ?

    
asked by anonymous 13.09.2016 / 21:56

1 answer

1

There's something wrong there! See:

The faturar() method is found on the Controller. So first you will not be able to access this method without loading your Controller into View , and second, this is conceptually wrong, since View does not "see" Controller , see image at the end of the answer, and third even if you did this, you are passing a% argument to% pro method that is not defined in the signature.

You did not show where the data that is being entered in the baixado is coming from, but it can be understood that it comes from a query; you have shown the li method that just returns a boolean field. You must faturar() in such a way that already delivered to View if the service order is downloaded or not.

    
14.09.2016 / 00:40