在我看来,我有以下输出:
stdClass Object ( [course_id] => 13 [title] => Design Illustration for Beginners).
这是在 $course 对象上使用 print_r() 的结果。这是模型中它背后的代码:
function loadMyTaughtCourses($email)
{
$this->db->select('*');
$this->db->where('email', $email);
$this->db->from('course');
$query = $this->db->get();
if ( $query->num_rows() > 0 )
{
return $query->result();
} else {
return FALSE;
}
}
这里的问题是我无法仅访问属性。我这样做了:
foreach($taughtCoursesInfo as &$course)
{
echo $course->title . "<br>";
}
然后我得到这个:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/profile.php
Line Number: 14
知道为什么吗?通常我会做 $object->property 并且有效。
提前致谢,