Documentation

RouteCollectionInterface

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 ran.

Table of Contents

add()  : mixed
Adds a single route to the collection.
addPlaceholder()  : mixed
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()  : string|Closure|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()  : mixed
Returns the raw array of available routes.
isRedirect()  : bool
Determines if the route is a redirecting route.
reverseRoute()  : string|false
Attempts to look up a route based on it's destination.
set404Override()  : RouteCollectionInterface
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()  : RouteCollectionInterface
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()  : mixed
Sets the default controller to use when no other controller has been specified.
setDefaultMethod()  : mixed
Sets the default method to call on the controller when no other method has been set in the route.
setDefaultNamespace()  : mixed
Sets the default namespace to use for Controllers when no other namespace has been specified.
setTranslateURIDashes()  : mixed
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()  : mixed
Returns the current value of the translateURIDashes setting.

Methods

add()

Adds a single route to the collection.

public add(string $from, array<string|int, mixed>|string $to[, array<string|int, mixed> $options = null ]) : mixed
Parameters
$from : string
$to : array<string|int, mixed>|string
$options : array<string|int, mixed> = null
Return values
mixed

addPlaceholder()

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(string|array<string|int, mixed> $placeholder[, string $pattern = null ]) : mixed

You can pass an associative array as $placeholder, and have multiple placeholders added at once.

Parameters
$placeholder : string|array<string|int, mixed>
$pattern : string = null
Return values
mixed

get404Override()

Returns the 404 Override setting, which can be null, a closure or the controller/string.

public get404Override() : string|Closure|null
Return values
string|Closure|null

getDefaultController()

Returns the name of the default controller. With Namespace.

public getDefaultController() : string
Return values
string

getDefaultMethod()

Returns the name of the default method to use within the controller.

public getDefaultMethod() : string
Return values
string

getHTTPVerb()

Returns the current HTTP Verb being used.

public getHTTPVerb() : string
Return values
string

getRedirectCode()

Grabs the HTTP status code from a redirecting Route.

public getRedirectCode(string $from) : int
Parameters
$from : string
Return values
int

getRoutes()

Returns the raw array of available routes.

public getRoutes() : mixed
Return values
mixed

isRedirect()

Determines if the route is a redirecting route.

public isRedirect(string $from) : bool
Parameters
$from : string
Return values
bool

reverseRoute()

Attempts to look up a route based on it's destination.

public reverseRoute(string $search, array<string|int, mixed> ...$params) : string|false

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
$params : array<string|int, mixed>
Return values
string|false

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 ]) : RouteCollectionInterface

This setting is passed to the Router class and handled there.

Parameters
$callable : callable|null = null
Return values
RouteCollectionInterface

setAutoRoute()

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) : RouteCollectionInterface

If FALSE, will stop searching and do NO automatic routing.

Parameters
$value : bool
Return values
RouteCollectionInterface

setDefaultController()

Sets the default controller to use when no other controller has been specified.

public setDefaultController(string $value) : mixed
Parameters
$value : string
Return values
mixed

setDefaultMethod()

Sets the default method to call on the controller when no other method has been set in the route.

public setDefaultMethod(string $value) : mixed
Parameters
$value : string
Return values
mixed

setDefaultNamespace()

Sets the default namespace to use for Controllers when no other namespace has been specified.

public setDefaultNamespace(string $value) : mixed
Parameters
$value : string
Return values
mixed

setTranslateURIDashes()

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) : mixed

...

Parameters
$value : bool
Return values
mixed

shouldAutoRoute()

Returns the flag that tells whether to autoRoute URI against Controllers.

public shouldAutoRoute() : bool
Return values
bool

shouldTranslateURIDashes()

Returns the current value of the translateURIDashes setting.

public shouldTranslateURIDashes() : mixed
Return values
mixed

Search results