0

我有两个功能getCompanyDetailsgetHostingDetails

第一个数据库getCompanyDetails工作正常,但getHostingDetails显示

Trying to get property of non-object

获取公司详细信息:

控制器: $data['companyName'] = $this->quote->getCompanyDetails()->companyName;

模型:

public function getCompanyDetails()
{
    $this->db->select('companyName,companySlogan,companyContact,
                       companyEmail,companyWebsite,companyPhone,
                       companyFax,companyAddress');

    $this->db->from('companyDetails');
    $result = $this->db->get();

    if($result->num_rows()<1)
    {
        return FALSE;
    }else{
        return $result->row();
    }
}

获取主机详细信息:

控制器:

$data['hostingRequired'] = $this->quote->getHostingDetails()->hostingRequired;

模型:

public function getHostingDetails()
{
    $this->db->select('hostingRequired,domainRequired,domainToBeReged,
                       domaintoBeReged0,domainTransfer,domainToBeTransfered,
                       domainToBeTransfered0,currentHosting');

    $this->db->from('hostingDetails');
    $result = $this->db->get();

    if($result->num_rows()<1)
    {
        return FALSE;
    }else{
        return $result->row();
    }               
}
4

3 回答 3

1

那么在您的函数中,如果没有返回行,get您的代码可能会返回您。false您可能需要在检索详细信息之前进行检查。例子:

$details = $this->quote->getHostingDetails();
if($details){
    $data['hostingRequired'] = $details->hostingRequired;
}
于 2012-04-08T02:17:43.040 回答
1

好吧,一个方法返回一个对象 from$result->row()和另一个false. 您不能在false.

false没有找到记录时返回。所以你需要在使用它之前检查返回值。

于 2012-04-08T02:17:51.877 回答
0

问题可能是您如何在控制器中使用这些功能。如果其中任何一个返回 FALSE,则

$this->quote->getHostingDetails()->hostingRequired;

会给你错误。尝试

if ($row = $this->quote->getHostingDetails()) {
    echo $row->hostingRequired;
}
于 2012-04-08T02:19:08.427 回答