이 tutorial에서는 PHP에서 RESTful API를 만드는 방법을 설명합니다. 내 문제는 섹션의 코드와 관련이 있습니다. .I 복사/넷빈즈의 코드를 붙여 넣어이 코드에 대한 메시지를 얻을 :코드에서 구문 오류가있는 곳을 찾을 수 없습니다
$this->User = $User;
내가 편집기에서 얻을 메시지는 변수 $이 예기치 않은 것을입니다. 여기서 오류가 어디 있는지 찾을 수 없습니다. 감사합니다. .
class MyAPI extends API
{
protected $User;
public function __construct($request, $origin) {
parent::__construct($request);
// Abstracted out for example
$APIKey = new Models\APIKey();
$User = new Models\User();
if (!array_key_exists('apiKey', $this->request)) {
throw new Exception('No API Key provided');
} else if (!$APIKey->verifyKey($this->request['apiKey'], $origin)) {
throw new Exception('Invalid API Key');
} else if (array_key_exists('token', $this->request) &&
!$User->get('token', $this->request['token']))
throw new Exception('Invalid User Token');
}
$this->User = $User;
}
/**
* Example of an Endpoint
*/
protected function example() {
if ($this->method == 'GET') {
return "Your name is " . $this->User->name;
} else {
return "Only accepts GET requests";
}
}
}
그 줄 앞에 코드를 추가하십시오. 아마';'또는'}'가 누락되었을 것입니다. 이것이'$ this'가 예기치 않은 이유입니다. – Niels
더 많은 코드를 게시하십시오 (오류 주위에 5-10 줄). – Jonathan
무슨 코드입니까? } –