I am using Micro Application to develop API, the first code is correct:
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo ERROR_C05;
});
but when i use json response:
$app->notFound(function () use ($app) {
$response = new \Phalcon\Http\Response();
$response->setContentType('application/json', 'utf-8');
$response->setContent(json_encode(ERROR_C05, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$response->setStatusCode(404, "Not Found")->sendHeaders();
return $response;
});
The page is nothing to reply, I promise the json syntax is correct as I am using it to handle API's valid request. I think this is also bugs??? why response is not the same expectation???