[英]Message: Trying to get property of non-object mvc framework Codeigniter
I'm trying to echo/get the values in my table but I having a Message: Trying to get property of non-object我正在尝试回显/获取表中的值,但我收到一条消息:试图获取非对象的属性
Like this one像这个
<tr class="project-overview-customer">
<td class="bold"><?php echo _l('dev_oqood_status'); ?></td>
<td><?php echo $developer->dev_oqood_status; ?></td>
</tr>
<tr class="project-overview-customer">
<td class="bold"><?php echo _l('dev_contact'); ?></td>
<td><?php echo $developer->dev_contact; ?></td>
</tr>
on my Model i have this在我的模型上我有这个
public function get_developer($id = '', $where = array())
{
$this->db->where($where);
if (is_numeric($id)) {
$this->db->where('project_id', $id);
$developer = $this->db->get('tbldevdetails')->row();
print_r($developer); die();
}
return $this->db->get('tbldevdetails')->result_array();
}
Then When I do print_r($project); die();
然后当我做
print_r($project); die();
print_r($project); die();
stdClass Object ( [dev_id] => 20 [project_id] => 49 [dev_devloper] => [dev_purchase_date] => 2018-02-27 [dev_handover_date] => 2018-02-27 [dev_oqood_status] => Mengaw [dev_contact] => 0 [dev_email] => Mengaw [dev_landline] => Mengaw [dev_mobile] => Mengaw )
Why I have this error?为什么我有这个错误? Anyone can guide me?
任何人都可以指导我吗?
$this->db->get('tbldevdetails')->row();
(which is what you are running print_r()
on returns an object. Which you are correctly accessing with <?php echo $developer->dev_oqood_status; ?>
. However... (这是您运行
print_r()
返回一个对象。您使用<?php echo $developer->dev_oqood_status; ?>
正确访问该对象。但是...
You are not returning $this->db->get('tbldevdetails')->row();
你没有返回
$this->db->get('tbldevdetails')->row();
you are returning $this->db->get('tbldevdetails')->result_array();
你正在返回
$this->db->get('tbldevdetails')->result_array();
.. This is an Array which you would access like $developer[0]['dev_oqood_status']
.. 这是一个您可以像
$developer[0]['dev_oqood_status']
一样访问的数组
So change your function get_developer
to return $developer;
所以改变你的函数
get_developer
以return $developer;
instead.反而。
Also know the difference between Result Rows And Result Arrays from the codeigniter framework还从 codeigniter 框架中了解了Result Rows和Result Arrays之间的区别
You are using ->result_array()
to get the $developer
, so $developer
is not an object, but is instead an array.您正在使用
->result_array()
来获取$developer
,因此$developer
不是一个对象,而是一个数组。 You should return an object instead by using ->result()
.您应该使用
->result()
返回一个对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.