RouteCollectionInterface
in
Interface RouteCollectionInterface
A Route Collection's sole job is to hold a series of routes. The required number of methods is kept very small on purpose, but implementors may add a number of additional methods to customize how the routes are defined.
The RouteCollection provides the Router with the routes so that it can determine which controller should be run.
Table of Contents
Methods
- add() : RouteCollectionInterface
- Adds a single route to the collection.
- addPlaceholder() : RouteCollectionInterface
- Registers a new constraint with the system. Constraints are used by the routes as placeholders for regular expressions to make defining the routes more human-friendly.
- get404Override() : callable(string): Array|string|null
- Returns the 404 Override setting, which can be null, a closure or the controller/string.
- getDefaultController() : string
- Returns the name of the default controller. With Namespace.
- getDefaultMethod() : string
- Returns the name of the default method to use within the controller.
- getHTTPVerb() : string
- Returns the current HTTP Verb being used.
- getRedirectCode() : int
- Grabs the HTTP status code from a redirecting Route.
- getRoutes() : array<string|int, mixed>
- Returns the raw array of available routes.
- isRedirect() : bool
- Determines if the route is a redirecting route.
- reverseRoute() : false|string
- Attempts to look up a route based on its destination.
- set404Override() : self
- Sets the class/method that should be called if routing doesn't find a match. It can be either a closure or the controller/method name exactly like a route is defined: Users::index
- setAutoRoute() : self
- If TRUE, the system will attempt to match the URI against Controllers by matching each segment against folders/files in APPPATH/Controllers, when a match wasn't found against defined routes.
- setDefaultController() : RouteCollectionInterface
- Sets the default controller to use when no other controller has been specified.
- setDefaultMethod() : RouteCollectionInterface
- Sets the default method to call on the controller when no other method has been set in the route.
- setDefaultNamespace() : RouteCollectionInterface
- Sets the default namespace to use for Controllers when no other namespace has been specified.
- setTranslateURIDashes() : RouteCollectionInterface
- Tells the system whether to convert dashes in URI strings into underscores. In some search engines, including Google, dashes create more meaning and make it easier for the search engine to find words and meaning in the URI for better SEO. But it doesn't work well with PHP method names.
- shouldAutoRoute() : bool
- Returns the flag that tells whether to autoRoute URI against Controllers.
- shouldTranslateURIDashes() : bool
- Returns the current value of the translateURIDashes setting.
- shouldUseSupportedLocalesOnly() : bool
- Get the flag that limit or not the routes with {locale} placeholder to App::$supportedLocales
Methods
add()
Adds a single route to the collection.
public
add(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
-
The route path (with placeholders or regex)
- $to : array<string|int, mixed>|callable(mixed...): Array|string
-
The route handler
- $options : array<string|int, mixed>|null = null
-
The route options
Return values
RouteCollectionInterfaceaddPlaceholder()
Registers a new constraint with the system. Constraints are used by the routes as placeholders for regular expressions to make defining the routes more human-friendly.
public
addPlaceholder(array<string|int, mixed>|string $placeholder[, string|null $pattern = null ]) : RouteCollectionInterface
You can pass an associative array as $placeholder, and have multiple placeholders added at once.
Parameters
- $placeholder : array<string|int, mixed>|string
- $pattern : string|null = null
-
The regex pattern
Return values
RouteCollectionInterfaceget404Override()
Returns the 404 Override setting, which can be null, a closure or the controller/string.
public
get404Override() : callable(string): Array|string|null
Return values
callable(string): Array|string|nullgetDefaultController()
Returns the name of the default controller. With Namespace.
public
getDefaultController() : string
Return values
stringgetDefaultMethod()
Returns the name of the default method to use within the controller.
public
getDefaultMethod() : string
Return values
stringgetHTTPVerb()
Returns the current HTTP Verb being used.
public
getHTTPVerb() : string
Return values
stringgetRedirectCode()
Grabs the HTTP status code from a redirecting Route.
public
getRedirectCode(string $routeKey) : int
Parameters
- $routeKey : string
Return values
intgetRoutes()
Returns the raw array of available routes.
public
getRoutes() : array<string|int, mixed>
Return values
array<string|int, mixed>isRedirect()
Determines if the route is a redirecting route.
public
isRedirect(string $routeKey) : bool
Parameters
- $routeKey : string
Return values
boolreverseRoute()
Attempts to look up a route based on its destination.
public
reverseRoute(string $search, int|string ...$params) : false|string
If a route exists:
'path/(:any)/(:any)' => 'Controller::method/$1/$2'
This method allows you to know the Controller and method and get the route that leads to it.
// Equals 'path/$param1/$param2'
reverseRoute('Controller::method', $param1, $param2);
Parameters
- $search : string
-
Named route or Controller::method
- $params : int|string
Return values
false|string —The route (URI path relative to baseURL) or false if not found.
set404Override()
Sets the class/method that should be called if routing doesn't find a match. It can be either a closure or the controller/method name exactly like a route is defined: Users::index
public
set404Override([callable|null $callable = null ]) : self
This setting is passed to the Router class and handled there.
Parameters
- $callable : callable|null = null
Return values
selfsetAutoRoute()
If TRUE, the system will attempt to match the URI against Controllers by matching each segment against folders/files in APPPATH/Controllers, when a match wasn't found against defined routes.
public
setAutoRoute(bool $value) : self
If FALSE, will stop searching and do NO automatic routing.
Parameters
- $value : bool
Return values
selfsetDefaultController()
Sets the default controller to use when no other controller has been specified.
public
setDefaultController(string $value) : RouteCollectionInterface
Parameters
- $value : string
Return values
RouteCollectionInterfacesetDefaultMethod()
Sets the default method to call on the controller when no other method has been set in the route.
public
setDefaultMethod(string $value) : RouteCollectionInterface
Parameters
- $value : string
Return values
RouteCollectionInterfacesetDefaultNamespace()
Sets the default namespace to use for Controllers when no other namespace has been specified.
public
setDefaultNamespace(string $value) : RouteCollectionInterface
Parameters
- $value : string
Return values
RouteCollectionInterfacesetTranslateURIDashes()
Tells the system whether to convert dashes in URI strings into underscores. In some search engines, including Google, dashes create more meaning and make it easier for the search engine to find words and meaning in the URI for better SEO. But it doesn't work well with PHP method names.
public
setTranslateURIDashes(bool $value) : RouteCollectionInterface
...
Parameters
- $value : bool
Return values
RouteCollectionInterfaceshouldAutoRoute()
Returns the flag that tells whether to autoRoute URI against Controllers.
public
shouldAutoRoute() : bool
Return values
boolshouldTranslateURIDashes()
Returns the current value of the translateURIDashes setting.
public
shouldTranslateURIDashes() : bool
Return values
boolshouldUseSupportedLocalesOnly()
Get the flag that limit or not the routes with {locale} placeholder to App::$supportedLocales
public
shouldUseSupportedLocalesOnly() : bool