/** * @param int $code * @param array $data */ private function toJson($code, $data) { $this->response->header('Content-Type', 'application/json'); $this->response->status($code); if (defined('JSON_PRETTY_PRINT')) { $this->response->body(json_encode($data, JSON_PRETTY_PRINT)); } else { $this->response->body(json_encode($data)); } }
/** * Halt * * Stop the application and immediately send the response with a * specific status and body to the HTTP client. This may send any * type of response: info, success, redirect, client error, or server error. * If you need to render a template AND customize the response status, * use the application's `render()` method instead. * * @param int $status The HTTP response status * @param string $message The HTTP response body */ public function halt($status, $message = '') { $this->cleanBuffer(); $this->response->status($status); $this->response->body($message); $this->stop(); }
/** * convert array to json and parsing to body * @param $message * @param int $statusCode */ protected function writeToJSON($message, $statusCode = 200) { $this->response->status($statusCode); $this->response['Content-Type'] = 'application/json'; $this->response->body(json_encode($message)); }