0

一切似乎都很好,但我不断收到以下错误:

遇到 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:models/ordermodel.php

行号:24

遇到 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:models/ordermodel.php

行号:31

==================================================== ===============

在视图中,我只是回显 $company_name

控制器:

            $city = $this->ordermodel->get_city($order_reference);
            $customerCompanyName = $this->ordermodel->get_company_name($order_reference);
            $data['company_name'] = $customerCompanyName;

模型:

function get_city($ordernumber) {
    $this->db->where('order_number', $ordernumber);
    $city = $this->db->get('order');

    return $city->row()->city;
}

function get_company_name($ordernumber) {
    $this->db->where('order_number', $ordernumber);
    $companyname = $this->db->get('order');

    return $companyname->row()->company_name;
}
4

2 回答 2

1

使用他们的result()方法,它应该消除你所有的错误

$row = $city->result(); return $row->city;

于 2013-02-04T13:16:53.140 回答
0

似乎您的查询没有结果,请尝试:

function get_company_name($ordernumber) {
    $this->db->where('order_number', $ordernumber);
    $companyname = $this->db->get('order');

    if ($companyname->num_rows() > 0) {
        return $companyname->row()->company_name;
    }
    else {
        return '';
    }
}
于 2013-02-04T11:41:59.260 回答