我有两个函数getCompanyDetails
和getHostingDetails
第一个数据库getCompanyDetails
正常,但getHostingDetails
显示
Trying to get property of non-object
getCompanyDetails:
控制器: $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();
}
}
getHostingDetails:
控制器:
$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();
}
}
答案 0 :(得分:1)
在您的get
函数中,如果没有返回行,您的代码可能会返回false
。您可能需要在检索详细信息之前进行检查。例如:
$details = $this->quote->getHostingDetails();
if($details){
$data['hostingRequired'] = $details->hostingRequired;
}
答案 1 :(得分:1)
好吧,一个方法从$result->row()
和另一个false
返回一个对象。您无法在false
上调用方法。
false
。因此,您需要在使用之前检查返回值。
答案 2 :(得分:0)
问题可能在于如何在控制器中使用这些功能。如果其中任何一个返回FALSE,那么
$this->quote->getHostingDetails()->hostingRequired;
会给你错误。尝试
if ($row = $this->quote->getHostingDetails()) {
echo $row->hostingRequired;
}