Output Class
The output class contains the methods to deal with HTTP header information.
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:
Output::$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
Output::set_header('Content-Type', 'application/pdf');
// It will be called downloaded.pdf
Output::set_header('Content-Disposition', 'attachment; filename="downloaded.pdf"');
// Set no cache
Output::set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
Output::set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
Output::set_header('Pragma', 'no-cache');
// More examples
Output::set_header('Content-Language', 'en');
Output::set_header('Content-Type', 'text/html; charset=utf-8');
|
set_header($headers)
The set_headers method allows set multiple custom HTTP headers.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$headers |
Required |
Array with name/value pairs of the headers to add |
|
Returns |
void |
Example |
$headers = array(
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Pragma' => 'no-cache'
);
Output::set_headers($headers);
// Above method will do the same as
Output::set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
Output::set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
Output::set_header('Pragma', 'no-cache');
|
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 |
Output::send_headers();
|
Note that you normally don't have to call this method manually. FuelPHP 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');
|