Trait RedirectTrait
Trait to implement redirect route functionality.
Redirect route will perform an immediate redirect. Redirect routes are useful when you want to have Routing layer redirects occur in your application, for when URLs move.
Redirection is signaled by an exception that halts route matching and defines the redirect URL and status code.
Property Summary
-
$redirect public
arrayThe location to redirect to.
Method Summary
-
__construct() public
Constructor
-
match() public
There is no reverse routing redirection routes.
-
parse() public
Parses a string URL into an array. Parsed URLs will result in an automatic redirection.
-
setStatus() public
Sets the HTTP status
Method Detail
__construct() ¶ public
__construct(string $template, array $defaults = [], array<string, mixed> $options = [])
Constructor
Parameters
-
string$template Template string with parameter placeholders
-
array$defaults optional Defaults for the route. Either a redirect=>value array or a CakePHP array URL.
-
array<string, mixed>$options optional Array of additional options for the Route
match() ¶ public
match(array $url, array $context = []): string|null
There is no reverse routing redirection routes.
Parameters
-
array$url Array of parameters to convert to a string.
-
array$context optional Array of request context parameters.
Returns
string|nullAlways null, string return result unused.
parse() ¶ public
parse(string $url, string $method = ''): array|null
Parses a string URL into an array. Parsed URLs will result in an automatic redirection.
Parameters
-
string$url The URL to parse.
-
string$method optional The HTTP method being used.
Returns
array|nullNull on failure. An exception is raised on a successful match. Array return type is unused.
Throws
Cake\Http\Exception\RedirectExceptionAn exception is raised on successful match. This is used to halt route matching and signal to the middleware that a redirect should happen.
setStatus() ¶ public
setStatus(int $status): $this
Sets the HTTP status
Parameters
-
int$status The status code for this route
Returns
$this