Class **Phalcon\\Http\\Response** ================================= *implements* :doc:`Phalcon\\Http\\ResponseInterface `, :doc:`Phalcon\\Di\\InjectionAwareInterface ` .. role:: raw-html(raw) :format: html :raw-html:`Source on GitHub` Part of the HTTP cycle is return responses to the clients. Phalcon\\HTTP\\Response is the Phalcon component responsible to achieve this task. HTTP responses are usually composed by headers and body. .. code-block:: php setStatusCode(200, "OK"); $response->setContent("Hello"); $response->send(); Methods ------- public **__construct** ([*string* $content], [*int* $code], [*string* $status]) Phalcon\\Http\\Response constructor public **setDI** (:doc:`Phalcon\\DiInterface ` $dependencyInjector) Sets the dependency injector public **getDI** () Returns the internal dependency injector public **setStatusCode** (*unknown* $code, [*unknown* $message]) Sets the HTTP response code .. code-block:: php setStatusCode(404, "Not Found"); public **getStatusCode** () Returns the status code .. code-block:: php getStatusCode()); public **setHeaders** (:doc:`Phalcon\\Http\\Response\\HeadersInterface ` $headers) Sets a headers bag for the response externally public **getHeaders** () Returns headers set by the user public **setCookies** (:doc:`Phalcon\\Http\\Response\\CookiesInterface ` $cookies) Sets a cookies bag for the response externally public :doc:`Phalcon\\Http\\Response\\CookiesInterface ` **getCookies** () Returns coookies set by the user public :doc:`Phalcon\\Http\\Response ` **setHeader** (*string* $name, *string* $value) Overwrites a header in the response .. code-block:: php setHeader("Content-Type", "text/plain"); public **setRawHeader** (*unknown* $header) Send a raw header to the response .. code-block:: php setRawHeader("HTTP/1.1 404 Not Found"); public **resetHeaders** () Resets all the stablished headers public **setExpires** (*DateTime* $datetime) Sets a Expires header to use HTTP cache .. code-block:: php response->setExpires(new DateTime()); public **setCache** (*unknown* $minutes) Sets Cache headers to use HTTP cache .. code-block:: php response->setCache(60); public **setNotModified** () Sends a Not-Modified response public :doc:`Phalcon\\Http\\Response ` **setContentType** (*string* $contentType, [*string* $charset]) Sets the response content-type mime, optionally the charset .. code-block:: php setContentType('application/pdf'); $response->setContentType('text/plain', 'UTF-8'); public **setEtag** (*unknown* $etag) Set a custom ETag .. code-block:: php setEtag(md5(time())); public :doc:`Phalcon\\Http\\Response ` **redirect** ([*string|array* $location], [*boolean* $externalRedirect], [*int* $statusCode]) Redirect by HTTP to another action or URL .. code-block:: php redirect("posts/index"); $response->redirect("http://en.wikipedia.org", true); $response->redirect("http://www.example.com/new-location", true, 301); //Making a redirection based on a named route $response->redirect(array( "for" => "index-lang", "lang" => "jp", "controller" => "index" )); public **setContent** (*unknown* $content) Sets HTTP response body .. code-block:: php setContent("

Hello!

"); public :doc:`Phalcon\\Http\\Response ` **setJsonContent** (*mixed* $content, [*int* $jsonOptions], [*unknown* $depth]) Sets HTTP response body. The parameter is automatically converted to JSON .. code-block:: php setJsonContent(array("status" => "OK")); public :doc:`Phalcon\\Http\\Response ` **appendContent** (*string* $content) Appends a string to the HTTP response body public **getContent** () Gets the HTTP response body public **isSent** () Check if the response is already sent public **sendHeaders** () Sends headers to the client public **sendCookies** () Sends cookies to the client public **send** () Prints out HTTP response to the client public :doc:`Phalcon\\Http\\Response ` **setFileToSend** (*string* $filePath, [*string* $attachmentName], [*unknown* $attachment]) Sets an attached file to be sent at the end of the request