Response Class
The response class contains the methods to deal with HTTP response and browser output.
Setting the Status Header
The status header is treated as a "special" header in Fuel. You do not set it as you would
other headers. The status header is set as follows in the controller:
$this->response->status = 404;
You simply set the $status variable to the status number for the request.
set_header($name, $value)
The set_header method allows set custom HTTP headers.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
Required |
Name of the header to add. Note that names are unique, overwriting each other if the same name is used. |
$value |
Required |
The string that needs to be added to the HTTP header. |
|
Returns |
void |
Example |
// We'll be outputting a PDF
Response::set_header('Content-Type', 'application/pdf');
// It will be called downloaded.pdf
Response::set_header('Content-Disposition', 'attachment; filename="downloaded.pdf"');
// Set no cache
Response::set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
Response::set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
Response::set_header('Pragma', 'no-cache');
// More examples
Response::set_header('Content-Language', 'en');
Response::set_header('Content-Type', 'text/html; charset=utf-8');
|
send_headers()
The send_headers method sends the set headers out to the browser, including the HTTP status of the request.
Static |
Yes |
Parameters |
None |
Returns |
void |
Example |
Response::send_headers();
|
Note that you normally don't have to call this method manually. Fuel will take care of this as part of processing the request.
redirect($url = '', $method = 'location', $redirect_code = 302)
The redirect method offers different methods of redirecting to a new URL.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$url |
''
|
URL to redirect to. |
$method |
'location'
|
Redirection method to use. Supported are 'location' and 'refresh'. |
$redirect_code |
302
|
HTTP status code to send back as part of the redirect. |
|
Returns |
This method terminates the current script, it does not return. |
Example |
Response::redirect('http://example.com/home', 'refresh');
|