implements Phalcon\Http\ResponseInterface, Phalcon\DI\InjectionAwareInterface
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.
$response = new Phalcon\Http\Response(); $response->setStatusCode(200, "OK"); $response->setContent("<html><body>Hello</body></html>"); $response->send();
Phalcon\Http\Response constructor
Sets the dependency injector
Returns the internal dependency injector
Sets the HTTP response code
$response->setStatusCode(404, "Not Found");
Sets a headers bag for the response externally
Returns headers set by the user
Sets a cookies bag for the response externally
Returns coookies set by the user
Overwrites a header in the response
$response->setHeader("Content-Type", "text/plain");
Send a raw header to the response
$response->setRawHeader("HTTP/1.1 404 Not Found");
Resets all the stablished headers
Sets a Expires header to use HTTP cache
$this->response->setExpires(new DateTime());
Sends a Not-Modified response
Sets the response content-type mime, optionally the charset
$response->setContentType('application/pdf'); $response->setContentType('text/plain', 'UTF-8');
Set a custom ETag
$response->setEtag(md5(time()));
Redirect by HTTP to another action or URL
//Using a string redirect (internal/external) $response->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" ));
Sets HTTP response body
$response->setContent("<h1>Hello!</h1>");
Sets HTTP response body. The parameter is automatically converted to JSON
$response->setJsonContent(array("status" => "OK")); $response->setJsonContent(array("status" => "OK"), JSON_NUMERIC_CHECK);
Appends a string to the HTTP response body
Gets the HTTP response body
Check if the response is already sent
Sends headers to the client
Sends cookies to the client
Prints out HTTP response to the client
Sets an attached file to be sent at the end of the request
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Http_Response.html