Php 尝试获取非对象和未定义变量的属性时出错:Codeigniter

Php 尝试获取非对象和未定义变量的属性时出错:Codeigniter,php,codeigniter,Php,Codeigniter,我面临以下错误: 尝试获取非对象和未定义变量php的属性 代码中的错误 控制器: function showDoctorInformation(){ $this->load->model('PatientModel'); $data['doctorinfo'] = $this->PatientModel->getDoctorInformation(); $this->parser->parse('patient_msgview', $d

我面临以下错误:

尝试获取非对象和未定义变量php的属性 代码中的错误

控制器:

function showDoctorInformation(){
    $this->load->model('PatientModel');
    $data['doctorinfo'] = $this->PatientModel->getDoctorInformation();
    $this->parser->parse('patient_msgview', $data);

}
型号:

function getDoctorId() {
        $this->db->from('person');
        $this->db->select('doctorId');
        $doctorId = $this->db->get()->result();
        return $doctorId;
    }

function getDoctorInformation() {


    $doctorId = $this->getDoctorId();

        $this->db->from('DoctorInfo');
        $this->db->where('doctorId', $doctorId);
        $this->db->select('name', 'surname', 'Bio', 'Address', 'img');
        $doctorinfo = $this->db->get()->result();
        return $doctorinfo;

}
视图:


我以前使用此方法显示过数据库中的信息,现在看不到错误。

返回

此方法将查询结果作为对象数组或 失败时为空数组

因此,您需要使用
->row()

在viwe中,您必须使用foreach循环获取数据

对于exm

foreach ($doctorinfo as $row)
{
        echo $row['title'];
        echo $row['name'];
        echo $row['body'];
}

函数getDoctorId仅在函数getDoctorInformation中调用,我尝试过,但仍然是相同的错误。是的,在使用更新后,我得到了以下错误:遇到PHP错误严重性:注意消息:未定义变量:doctorinfo文件名:views/patient\u msgview.PHP行号:100 Backtrace:File:/home/a15\u web01/web/application/views/patient\u msgview.PHP行:100函数:\错误\处理程序文件:/home/a15_web01/web/application/controllers/PatientController.php行:51函数:解析文件:/home/a15_web01/web/index.php行:292函数:还需要保存控制器代码和打印值($doctorinfo)这是我的控制器:*函数showDoctorInformation(){$this->load->model('PatientModel');$data['doctorinfo']=$this->PatientModel->getDoctorInformation();$this->parser->parse($patient\u msgview',$data);}**以及使用print\r($doctorinfo)时我看不到的值;使用
echo$this->db->last_query()
打印最后一个查询并进行检查
function getDoctorId() {
$this->db->select('doctorId');
$this->db->from('person');
$this->db->select('doctorId');
$query = $this->db->get();
if ($query->num_rows == 1) {
     $row=$query->row();// fetch single row
     return $row->doctorId;// get doctor id
} else {
    return FALSE;
}
}
foreach ($doctorinfo as $row)
{
        echo $row['title'];
        echo $row['name'];
        echo $row['body'];
}