Calling a function in Views in codeigniter

Asked

Viewed 1,705 times

2

I have that function in the 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 that 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 the Views that:

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

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

I’ve tried to: $somaPagar->valor, $somaPagar->$resultado and a lot of bad variants always error.

  • Put the complete Controller code, and something else the Model method seems inconsistent to me.

  • Virgilio... the complete function of the Controller does not fit here in the comments... I will do in the answer.

  • 1

    Ask the question.

  • Ready... I’m almost bald....

  • what error appears?

  • I am not able to make appear in the view the result of the account I am doing in models..

  • I understood what you want, in your attempts you said that always appeared errors, appeared some error php ?

  • yes Magichat... in all attempts, appeared that did not recognize the function or the variable did not exist... I checked N times and there was no error in typing... so I do not know what else to do.

  • Place the php error,

  • The PHP Error was encountered Severity: Notice Message: Undefined variable: result Filename: mapos/panel.php Line Number: 104 A PHP Error was encountered Severity: Notice Message: Trying to get Property of non-non-Object Filename: mapos/panel.php Line Number: 104 Total Value R$:

  • In the previous attempt, I put this in the view: echo 'Total Value R$: '.$sum->$result;

  • puts or points the section referring to line 104.

  • on line 104 is this: echo 'Total Value R$: '.$sum->$result;

Show 8 more comments

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();

}

Na View:

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

Codeigniter Reference Site - Generating Query Results

  • I changed the model and view and gave this error: A PHP Error was encountered Severity: Notice Message: Trying to get Property of non-object Filename: mapos/panel.php Line Number: 104

  • @Jardeldint I’m sorry I was on the mobile and it gets bad to see all the possibilities, I remade and edit, take a look now

  • now gave this: A Database Error Occurred Error Number: 1064 You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near 'YOUR QUERY' at line 1 YOUR QUERY Filename: /home/molu/public_html/ossystem/models/mapos_model.php Line Number: 119

  • 1

    it worked... hehehe.. I hadn’t seen YOUR QUERY... I switched to somaCR and it worked... THANK YOU FRIEND!!! Take the rope off my neck!

Browser other questions tagged

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