Class represents json output that is sent to clients via REST API interface. Output is standardized and consists of error message (if applicable) and custom formatted content. Example for index page: { "error": false, "content": "welcome to api." } If there was an error, the reason should be described within error property. HTTP status code is always 200, since server itself responded with no error.
Пример #1
0
 /**
  * Render data from payload
  *
  * @throws \Api\Exception\NotImplementedException
  *
  * @return \Phalcon\Http\ResponseInterface
  */
 protected function render(\Api\Model\Payload $payload)
 {
     $format = $this->request->getQuery('format', null, 'json');
     switch ($format) {
         case 'json':
             $contentType = 'application/json';
             $encoding = 'UTF-8';
             $content = json_encode($payload->toArray());
             break;
         default:
             throw new \Api\Exception\NotImplementedException(sprintf('Requested format %s is not supported yet.', $format));
             break;
     }
     //        $this->response->setStatusCode(200, 'OK');
     $this->response->setContentType($contentType, $encoding);
     $this->response->setContent($content);
     return $this->response->send();
 }