RedirectException
extends HttpException
in package
An exception subclass used by routing and application code to trigger a redirect.
The URL and status code are provided as constructor arguments.
throw new RedirectException('http://example.com/some/path', 301);
Additional headers can also be provided in the constructor, or using the addHeaders() method.
Table of Contents
Properties
- $_attributes : array<string|int, mixed>
- Array of attributes that are passed in from the constructor, and made available in the view when a development error is displayed.
- $_defaultCode : int
- Default exception code
- $_messageTemplate : string
- Template string that has attributes sprintf()'ed into it.
- $_responseHeaders : array<string|int, mixed>|null
- Array of headers to be passed to {@link \Cake\Http\Response::withHeader()}
- $headers : array<string, mixed>
Methods
- __construct() : mixed
- Constructor
- addHeaders() : $this
- Add headers to be included in the response generated from this exception
- getAttributes() : array<string|int, mixed>
- Get the passed in attributes
- getCode() : int
- getHeaders() : array<string, mixed>
- Returns array of response headers.
- removeHeader() : $this
- Remove a header from the exception.
- responseHeader() : array<string|int, mixed>|null
- Get/set the response header to be used
- setHeader() : void
- Set a single HTTP response header.
- setHeaders() : void
- Sets HTTP response headers.
Properties
$_attributes
Array of attributes that are passed in from the constructor, and made available in the view when a development error is displayed.
protected
array<string|int, mixed>
$_attributes
= []
$_defaultCode
Default exception code
protected
int
$_defaultCode
= 500
Tags
$_messageTemplate
Template string that has attributes sprintf()'ed into it.
protected
string
$_messageTemplate
= ''
$_responseHeaders
Array of headers to be passed to {@link \Cake\Http\Response::withHeader()}
protected
array<string|int, mixed>|null
$_responseHeaders
$headers
protected
array<string, mixed>
$headers
= []
Methods
__construct()
Constructor
public
__construct(string $target[, int $code = 302 ][, array<string|int, mixed> $headers = [] ]) : mixed
Parameters
- $target : string
-
The URL to redirect to.
- $code : int = 302
-
The exception code that will be used as a HTTP status code
- $headers : array<string|int, mixed> = []
-
The headers that should be sent in the unauthorized challenge response.
addHeaders()
Add headers to be included in the response generated from this exception
public
addHeaders(array<string|int, mixed> $headers) : $this
Use setHeaders()
instead.
Parameters
- $headers : array<string|int, mixed>
-
An array of
header => value
to append to the exception. If a header already exists, the new values will be appended to the existing ones.
Return values
$thisgetAttributes()
Get the passed in attributes
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getCode()
public
getCode() : int
Gets the Exception code.
Return values
intgetHeaders()
Returns array of response headers.
public
getHeaders() : array<string, mixed>
Return values
array<string, mixed>removeHeader()
Remove a header from the exception.
public
removeHeader(string $key) : $this
Use setHeaders()
instead.
Parameters
- $key : string
-
The header to remove.
Return values
$thisresponseHeader()
Get/set the response header to be used
public
responseHeader([array<string|int, mixed>|string|null $header = null ][, string|null $value = null ]) : array<string|int, mixed>|null
Use HttpException::setHeaders()
instead. Response headers
should be set for HttpException only.
Parameters
- $header : array<string|int, mixed>|string|null = null
-
A single header string or an associative array of "header name" => "header value"
- $value : string|null = null
-
The header value.
Return values
array<string|int, mixed>|nullsetHeader()
Set a single HTTP response header.
public
setHeader(string $header[, array<string|int, string>|string|null $value = null ]) : void
Parameters
- $header : string
-
Header name
- $value : array<string|int, string>|string|null = null
-
Header value
setHeaders()
Sets HTTP response headers.
public
setHeaders(array<string, mixed> $headers) : void
Parameters
- $headers : array<string, mixed>
-
Array of header name and value pairs.