Error Object of class stdClass could not be converted to string in codeigniter [closed]

0

I can not seem to get out of this place because of this error.

My model is as follows

public function conf($dados){
    $this->db->select('id');
    $this->db->where('senha',$dados);
    $query = $this->db->get('email');
    return $query->row();
}

and my controller looks like this:

public function fim(){
    $this->load->model('quest_model');
    $this->load->helper('quest');
    $data = $this->input->post('senha');
    $dados['quest'] = $this->email_model->emailconf($data);
    $dados['quest1'] = $this->quest_model->get_quest(); 
    $dados['quest2'] = $this->quest_model->get_quest2(); 
    $dados['ques1'] = $this->quest_model->get_ques(); 
    $dados['ques2'] = $this->quest_model->get_ques2(); 
    $this->load->view('quest/file',$dados);
}

I already changed the $ data for $ data ['p'] for example and did not stop giving this error in the same way.

The error you are giving is the following:     A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: quest/file.php

Line Number: 49

I used print_r and it is printing everything right, I can not find the error, if you can help me thank you very much

Thanks to everyone

    
asked by anonymous 18.09.2016 / 11:17

1 answer

1

It is not clear where this line 49 is where the error occurs, but I suppose it is in view . The view should be doing something like echo $dados['quest']; , and since $dados['quest'] is stdClass , this error message is displayed.

So I think you just have to do this:

$dados['quest'] = $this->email_model->emailconf($data)->idques;

Remove the breakpoint and test in this way that will probably fix the problem.

But be aware that I can not guarantee that the return will always be stdClass and that object will always have the idques property. In this case the consistency of the return is your responsibility to verify.

    
18.09.2016 / 18:04