php - 代码 Igniter(类 stdClass 的对象无法转换为字符串)错误

标签 php mysql arrays string codeigniter

这是我的模型:

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

这是我的 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);

}

这是我的观点:

<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>

所以我得到了这个错误:

遇到 PHP 错误

Severity: 4096

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

Filename:tema/alte.php

line Number: 67

请帮忙查找问题

PD:对不起,我的英语不是很好

最佳答案

你不应该使用 echo 来打印 Object - 普通情况下的返回值是 object 或 arrayuse :

 print_r($osn) ; 

查看输出然后循环它或使用对象 [$object_name->item]

关于php - 代码 Igniter(类 stdClass 的对象无法转换为字符串)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36927757/

相关文章:

php - Jquery 表单验证并通过 PHP 脚本使用 Mysql 数据库检查值

PHP 显示来自引用 URL 的标题

php - Paypal Restful - 无法解析主机

java - 智能产品推荐

java - 过滤数组中的差异

php - match() 函数和匹配变量

php - mySQL insert 只是行不通,但可以与其他表一起使用

php - SQL查询只显示第一个结果

c - 如何从文件中读取大量的float?

android - 在 ListView 中创建数组