Response


Description


The response class is responsible for sending output to the browser.


Methods


body(string $body)


The body method can be used to override the response body in the after method of your controller.


public function after()
{
	// Will prefix the response with "Hello, world!";
	
	$this->response->body('Hello, world!' . $this->response);
}

filter(callback $filter)


The filter method allows you to filter the output before sending it.


$this->response->filter('mb_strtolower');

// You can also use closures (anonymous functions) to filter the output.

$this->response->filter(function($body)
{
	return str_ireplace('[mako:assets]', Assets::location(), $body);
});

status(int $statusCode)


The status method is a helper method that makes it easy to send HTTP status headers. The status method will always reply using the same protocol version as the request.


$this->response->status(404); // Sends the 404 "Not Found" header.

redirect([string $location = '' [, int $statusCode = 302]])


The redirect method allows you to redirect a user to a different URL. The default status sent by the method is 302 Found but you can override this by setting the status code in the second parameter.


// Redirects to http://example.org/foo/bar

$this->response->redirect('foo/bar');

// Redirects to http://example.com with the "301 Moved Permanently" header

$this->response->redirect('http://example.com', 301);

cache()


Calling the cache method will enable response caching using ETags. This will reduse the bandwidth usage of your application.


$this->response->cache();