Returning Responses

Returning Responses

Part of the HTTP cycle is returning responses to clients. Phalcon\Http\Response is the Phalcon component designed to achieve this task. HTTP responses are usually composed by headers and body. The following is an example of basic usage:

//Getting a response instance
$response = new \Phalcon\Http\Response();

//Set status code
$response->setStatusCode(404, "Not Found");

//Set the content of the response
$response->setContent("Sorry, the page doesn't exist");

//Send response to the client
$response->send();

If you are using the full MVC stack there is no need to create responses manually. However, if you need to return a response directly from a controller’s action follow this example:

class FeedController extends