未定义的属性:stdClass :: codeigniter 3 with php 5.3.6

时间:2016-02-26 16:00:26

标签: php codeigniter

我正在使用带有php 5.3.6的codeigniter 3,并且在尝试回显$ row [0] - > ACOM时出现此错误;

Message: Undefined property: stdClass::$ACOM

的var_dump

var_dump($row[0]);
object(stdClass)#22 (1) { ["ACOM"]=> string(11) "43000005370" }

的print_r

print_r($row[0]);
stdClass Object ( [ACOM] => 43000005370 )

回波

echo $row[0]->ACOM;
Message: Undefined property: stdClass::$ACOM

如果我返回一个result_array(),我可以使用数组;

echo $row[0]['ACOM'];

显示43000005370

但我不知道对象发生了什么......

编辑:

我的模特:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Menu_model extends CI_MODEL
{   
    public function menuJoin($atec)
        {   
            $this->db->select('ACOM');
            $this->db->from(LIBRERIA1.'.AVSSAT');
            $this->db->where('ATEC',$atec);

            $query = $this->db->get();

            //return $query->result_array();
            return $query->result();
        }
}

我的控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Menu extends CI_Controller
{

    public function __construct()
        {
            parent::__construct();

        }

    public function index()
        {    
            $this->load->model('Menu_model');
            $datos=$this->Menu_model->menuJoin($_SESSION['MWCOME']);

            $this->load->view("comun/head");
            $this->load->view("menu/header_menu");
            $this->load->view("menu/menu", array( "row" =>  $datos) );
            $this->load->view("comun/footer");
        }
}

我的观点:

<?php
var_dump($row[0]);
echo $row[0]->ACOM;
?>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

你试过$ row [0] - &gt; ACOM; ?

the row[0] is a object based on 

print_r($row[0]);
stdClass Object ( [ACOM] => 43000005370 )

所以$ row [0] - &gt; ACOM会起作用。