Yilmer Avila Villarreal Yilmer Avila Villarreal - 7 months ago 201
PHP Question

Code Igniter (Object of class stdClass could not be converted to string) erro

this is my model:

function Countosweb(){
$sql="SELECT count(*) FROM `os` WHERE `status`='PENDIENTE ASIGNAR TÉCNICO'";
return $this->db->query($sql)->row();
}


this is my controller:

public function indexp() {
if((!$this->session->userdata('session_id')) || (!$this->session->userdata('logado'))){
redirect('mapos/login');
}
$this->data['ordensW'] = $this->mapos_model->getOsWeb();
$this->data['osn']= $this->mapos_model->Countosweb($sql);
$this->data['ordens'] = $this->mapos_model->getOsAbertas();
$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/panel';
//$this->session->set_flashdata('success','mensaje de prueba');
$this->load->view('tema/alte',$this->data);

}


and this is my view:

<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<?php
if($osn != null){echo '<span class="label label-warning">'.$osn.'</span>';} // this is the line which is occasinating the problem.
?>
</a>


so i got this error:

A PHP ERROR WAS ENCOUNTERED

Severity: 4096

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

Filename:tema/alte.php

line Number: 67

Please help to find the problem

PD: excuse me, my english is not very good

Answer

you shouldn't use echo to print Object - the return value in ordinary case is object or arrayuse :

 print_r($osn) ; 

to see the output then loop through it or use object [$object_name->item]

Comments