Codeiginter通知消息:上载网站后尝试获取非对象的属性

时间:2018-10-06 21:00:35

标签: codeigniter

我正在使用代码php Codeiginter在本地主机中使用apis建立网站,上传网站后一切正常,

  

遇到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);
    }

我的问题在哪里?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,问题出在,恢复的数据names的空间如下:

$_POST['first_name ']; 

解决方案只是我删除了空间:

 $_POST['first_name '];