我正在使用代码 php Codeiginter 在本地主机中使用 API 构建网站,上传网站后一切正常 此消息显示给我之后
遇到 PHP 错误严重性:注意
消息:尝试获取非对象的属性
此 API 方法:
public function getAdditionalsByAreaId($areaId)
{
if ($_SERVER['REQUEST_METHOD'] == "GET") :
$this->apiToken = $_SERVER['HTTP_APITOKEN'];
$partnerId = $this->jwtc->getUserIdFromToken($this->apiToken);
if (!count($this->PartnersModel->getPartnerInfoByToken($partnerId))) :
$this->output
->set_content_type('application/json')
->set_output(json_encode($this->resultheaders->forbidden(), JSON_UNESCAPED_UNICODE));
return;
endif;
if (!$this->checkIfAreaForPartner($partnerId, $areaId)) :
$this->output
->set_content_type('application/json')
->set_output(json_encode($this->resultheaders->forbidden(), JSON_UNESCAPED_UNICODE));
return;
endif;
$this->header = $this->resultheaders->success();
$rs = $this->AreasModel->getAdditionalsByAreaId($areaId);
$result = array(
'header' => $this->header,
'list' => $rs
);
$this->output
->set_content_type('application/json')
->set_output(json_encode($result, JSON_UNESCAPED_UNICODE));
endif;
}
private function getAdditionalsByAreaId($areaId)
{
return $this->AreasModel->getAdditionalsByAreaId($areaId);
}
而这个函数来获取 API 结果:
public function getAdditionalsByAreaId($areaId)
{
//
$curl = curl_init($this->datalayer->getApiUrl() . 'partners/areas/getAdditionalsByAreaId/' . $areaId);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'ApiToken:' . $this->datalayer->getApiToken(),
)
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Make it so the data coming back is put into a string
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
我的问题在哪里?
我解决了这个问题,问题出在,数据恢复names
有这样的空间:
$_POST['first_name '];
解决方案只是我删除了空间:
$_POST['first_name '];