Calling a function in Views in codeigniter

2

I have this function in models :

function sumContasReceber() {
    $this->db->select('lancamentos.*');
    $this->db->from('lancamentos');
    $somaCR = "SELECT SUM(valor) as SOMACR FROM 
            lancamentos where baixado = 0 AND tipo = 'receita'";
    $resultado = mysql_query($somaCR);      
    return $this->db->get()->result();    
}

And this function in Controllers :

public function index() {
    if((!$this->session->userdata('session_id')) || (!$this->session->userdata('logado'))){
        redirect('mapos/login');
    }

    $this->data['somaReceber'] = $this->mapos_model->sumContasReceber();
    $this->data['somaPagar'] = $this->mapos_model->sumContasPagar();
    $this->data['contasPagar'] = $this->mapos_model->getContasPagar();
    $this->data['contasReceber'] = $this->mapos_model->getContasReceber();
    $this->data['ordens'] = $this->mapos_model->getOsAbertas();
    $this->data['ordensAG'] = $this->mapos_model->getOsAgendamento();
    $this->data['ordensAP'] = $this->mapos_model->getOsAguardandoPecas();
    $this->data['ordensA'] = $this->mapos_model->getOsAndamento();
    $this->data['produtos'] = $this->mapos_model->getProdutosMinimo();
    $this->data['os'] = $this->mapos_model->getOsEstatisticas();
    $this->data['estatisticas_financeiro'] = $this->mapos_model->getEstatisticasFinanceiro();
    $this->data['menuPainel'] = 'Painel';
    $this->data['view'] = 'mapos/painel';
    $this->load->view('tema/topo',  $this->data);      
}

And in Views this:

echo 'Valor Total R$: '**aqui ta minha dificuldade**;

What do I put in View to call the result of the Model function?

I have tried: $somaPagar->valor , $somaPagar->$resultado and a lot of bad variants always from error.

    
asked by anonymous 10.09.2016 / 23:03

1 answer

3

Change the code as below:

function sumContasReceber() {

    $somaCR = "SELECT SUM(valor) as SOMACR FROM lancamentos
                          where baixado = 0 AND tipo = 'receita'";
    return  $this->db->query($somaCR)->row();

}

In View:

<?php echo $somaReceber->SOMACR; ?>

CodeIgniter Site Reference - Generating Query Results

    
10.09.2016 / 23:24