난 작곡가를 통해 슬림하게 설치했으며 간단한 REST API를 만들려고합니다. 나는 액세스하려고하면 나는 통과 할 수 있었다 약간 슬림 찾을 수없는 오류를했다Slim 3 Framework - setStatus에서 치명적인 오류가 발생했습니다.
require 'vendor/autoload.php';
$app = new \Slim\App();
$app->get('/getPoiInitialList', function ($request, $response, $args) {
//$app = \Slim\Slim::getInstance();
$app = new \Slim\App();
try
{
$db = getDB();
$sth = $db->prepare("SELECT * FROM wikivoyage_pois LIMIT 50");
$sth->execute();
$poiList = $sth->fetchAll(PDO::FETCH_OBJ);
if($poiList) {
$app->response->setStatus(200);
$app->response()->headers->set('Content-Type', 'application/json');
echo json_encode($poiList);
$db = null;
} else {
throw new PDOException('No records found.');
}
} catch(PDOException $e) {
$app->response()->setStatus(404);
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
});
// Run app
$app->run();
,하지만 지금 나는 다음과 같은 치명적인 오류를 얻고 공지 해요 :
내 현재 코드는 다음과 내 브라우저에서 엔드 포인트 :
Notice: Undefined property: Slim\App::$response in C:\xampp\htdocs\api\index.php on line 47 - the first setStatus
및
Fatal error: Call to a member function setStatus() on null in C:\xampp\htdocs\api\index.php on line 47
을 같은 줄에. 여기에 무슨 문제가 있을지에 대한 아이디어가 있습니까?
을, 나는주의 제거,하지만, 난 여전히 심각한 오류를 받고 있어요 :에 전화 정의되지 않은 메서드 Slim \ Http \ Response :: setStatus(). –
Claudio, 코드를 변경하십시오. $ app-> response() -> setStatus (404); ~ $ app-> response-> setStatus (404); –
http://docs.slimframework.com/response/status/ –