Properties

$defaultNamespace

$defaultNamespace : string

The namespace to be added to any Controllers.

Defaults to the global namespaces ()

Type

string

$defaultController

$defaultController : string

The name of the default controller to use when no other controller is specified.

Not used here. Pass-thru value for Router class.

Type

string

$defaultMethod

$defaultMethod : string

The name of the default method to use when no other method has been specified.

Not used here. Pass-thru value for Router class.

Type

string

$defaultPlaceholder

$defaultPlaceholder : string

The placeholder used when routing 'resources' when no other placeholder has been specified.

Type

string

$translateURIDashes

$translateURIDashes : boolean

Whether to convert dashes to underscores in URI.

Not used here. Pass-thru value for Router class.

Type

boolean

$autoRoute

$autoRoute : boolean

Whether to match URI against Controllers when it doesn't match defined routes.

Not used here. Pass-thru value for Router class.

Type

boolean

$override404

$override404 : string|\Closure

A callable that will be shown when the route cannot be matched.

Type

string|\Closure

$placeholders

$placeholders : array

Defined placeholders that can be used within the

Type

array

$routes

$routes : array

An array of all routes and their mappings.

Type

array

$routesOptions

$routesOptions : array

Array of routes options

Type

array

$HTTPVerb

$HTTPVerb : string

The current method that the script is being called by.

Type

string

$defaultHTTPMethods

$defaultHTTPMethods : array

The default list of HTTP methods (and CLI for command line usage) that is allowed if no other method is provided.

Type

array

$group

$group : string

The name of the current group, if any.

Type

string

$currentSubdomain

$currentSubdomain : string

The current subdomain.

Type

string

$currentOptions

$currentOptions : null

Stores copy of current options being applied during creation.

Type

null

$didDiscover

$didDiscover : boolean

A little performance booster.

Type

boolean

$moduleConfig

$moduleConfig : \Config\Modules

Handle to the modules config.

Type

\Config\Modules

Methods

addPlaceholder()

addPlaceholder(string|array  $placeholder, string  $pattern = null) : \CodeIgniter\Router\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.

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

Parameters

string|array $placeholder
string $pattern

Returns

\CodeIgniter\Router\RouteCollectionInterface

setDefaultNamespace()

setDefaultNamespace(  $value) : \CodeIgniter\Router\RouteCollectionInterface

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

Parameters

$value

Returns

\CodeIgniter\Router\RouteCollectionInterface

setDefaultController()

setDefaultController(  $value) : \CodeIgniter\Router\RouteCollectionInterface

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

Parameters

$value

Returns

\CodeIgniter\Router\RouteCollectionInterface

setDefaultMethod()

setDefaultMethod(  $value) : \CodeIgniter\Router\RouteCollectionInterface

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

Parameters

$value

Returns

\CodeIgniter\Router\RouteCollectionInterface

setTranslateURIDashes()

setTranslateURIDashes(boolean  $value) : \CodeIgniter\Router\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.

...

Parameters

boolean $value

Returns

\CodeIgniter\Router\RouteCollectionInterface

setAutoRoute()

setAutoRoute(boolean  $value) : \CodeIgniter\Router\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.

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

Parameters

boolean $value

Returns

\CodeIgniter\Router\RouteCollectionInterface

set404Override()

set404Override(callable|null  $callable = null) : \CodeIgniter\Router\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

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

Parameters

callable|null $callable

Returns

\CodeIgniter\Router\RouteCollectionInterface

get404Override()

get404Override() : string|\Closure|null

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

Returns

string|\Closure|null

setDefaultConstraint()

setDefaultConstraint(string  $placeholder) : \CodeIgniter\Router\RouteCollectionInterface

Sets the default constraint to be used in the system. Typically for use with the 'resource' method.

Parameters

string $placeholder

Returns

\CodeIgniter\Router\RouteCollectionInterface

getDefaultController()

getDefaultController() : string

Returns the name of the default controller. With Namespace.

Returns

string

getDefaultMethod()

getDefaultMethod() : string

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

Returns

string

getDefaultNamespace()

getDefaultNamespace() : string

Returns the default namespace as set in the Routes config file.

Returns

string

shouldTranslateURIDashes()

shouldTranslateURIDashes() : boolean

Returns the current value of the translateURIDashes setting.

Returns

boolean

shouldAutoRoute()

shouldAutoRoute() : boolean

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

Returns

boolean

getRoutes()

getRoutes(mixed  $verb = null) : array

Returns the raw array of available routes.

Parameters

mixed $verb

Returns

array

getRoutesOptions()

getRoutesOptions(string  $from = null) : array

Returns one or all routes options

Parameters

string $from

Returns

array

getHTTPVerb()

getHTTPVerb() : string

Returns the current HTTP Verb being used.

Returns

string

setHTTPVerb()

setHTTPVerb(string  $verb) : $this

Sets the current HTTP verb.

Used primarily for testing.

Parameters

string $verb

Returns

$this

map()

map(array  $routes = array(), array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

A shortcut method to add a number of routes at a single time.

It does not allow any options to be set on the route, or to define the method used.

Parameters

array $routes
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

add()

add(string  $from, array|string  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Adds a single route to the collection.

Example: $routes->add('news', 'Posts::index');

Parameters

string $from
array|string $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

addRedirect()

addRedirect(string  $from, string  $to, integer  $status = 302) : \CodeIgniter\Router\RouteCollection

Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes.

Parameters

string $from

The pattern to match against

string $to

Either a route name or a URI to redirect to

integer $status

The HTTP status code that should be returned with this redirect

Returns

\CodeIgniter\Router\RouteCollection

isRedirect()

isRedirect(string  $from) : boolean

Determines if the route is a redirecting route.

Parameters

string $from

Returns

boolean

getRedirectCode()

getRedirectCode(string  $from) : integer

Grabs the HTTP status code from a redirecting Route.

Parameters

string $from

Returns

integer

group()

group(string  $name,   $params) : void

Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like:

Example: // Creates route: admin/users $route->group('admin', function() { $route->resource('users'); });

Parameters

string $name

The name to group/prefix the routes with.

$params

resource()

resource(string  $name, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Creates a collections of HTTP-verb based routes for a controller.

Possible Options: 'controller' - Customize the name of the controller used in the 'to' route 'placeholder' - The regex used by the Router. Defaults to '(:any)' 'websafe' - - '1' if only GET and POST HTTP verbs are supported

Example:

 $route->resource('photos');

 // Generates the following routes:
 HTTP Verb | Path        | Action        | Used for...
 ----------+-------------+---------------+-----------------
 GET         /photos             index           an array of photo objects
 GET         /photos/new         new             an empty photo object, with default properties
 GET         /photos/{id}/edit   edit            a specific photo object, editable properties
 GET         /photos/{id}        show            a specific photo object, all properties
 POST        /photos             create          a new photo object, to add to the resource
 DELETE      /photos/{id}        delete          deletes the specified photo object
 PUT/PATCH   /photos/{id}        update          replacement properties for existing photo

If 'websafe' option is present, the following paths are also available:

 POST       /photos/{id}/delete delete
 POST        /photos/{id}        update

Parameters

string $name

The name of the resource/controller to route to.

array $options

An list of possible ways to customize the routing.

Returns

\CodeIgniter\Router\RouteCollectionInterface

presenter()

presenter(string  $name, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Creates a collections of HTTP-verb based routes for a presenter controller.

Possible Options: 'controller' - Customize the name of the controller used in the 'to' route 'placeholder' - The regex used by the Router. Defaults to '(:any)'

Example:

 $route->presenter('photos');

 // Generates the following routes:
 HTTP Verb | Path        | Action        | Used for...
 ----------+-------------+---------------+-----------------
 GET         /photos             index           showing all array of photo objects
 GET         /photos/show/{id}   show            showing a specific photo object, all properties
 GET         /photos/new         new             showing a form for an empty photo object, with default properties
 POST        /photos/create      create          processing the form for a new photo
 GET         /photos/edit/{id}   edit            show an editing form for a specific photo object, editable properties
 POST        /photos/update/{id} update          process the editing form data
 GET         /photos/remove/{id} remove          show a form to confirm deletion of a specific photo object
 POST        /photos/delete/{id} delete          deleting the specified photo object

Parameters

string $name

The name of the controller to route to.

array $options

An list of possible ways to customize the routing.

Returns

\CodeIgniter\Router\RouteCollectionInterface

match()

match(array  $verbs = array(), string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a single route to match for multiple HTTP Verbs.

Example: $route->match( ['get', 'post'], 'users/(:num)', 'users/$1);

Parameters

array $verbs
string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

get()

get(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to GET requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

post()

post(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to POST requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

put()

put(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to PUT requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

delete()

delete(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to DELETE requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

head()

head(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to HEAD requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

patch()

patch(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to PATCH requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

options()

options(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to OPTIONS requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

cli()

cli(string  $from, string|array  $to, array  $options = null) : \CodeIgniter\Router\RouteCollectionInterface

Specifies a route that is only available to command-line requests.

Parameters

string $from
string|array $to
array $options

Returns

\CodeIgniter\Router\RouteCollectionInterface

environment()

environment(string  $env, \Closure  $callback) : \CodeIgniter\Router\RouteCollectionInterface

Limits the routes to a specified ENVIRONMENT or they won't run.

Parameters

string $env
\Closure $callback

Returns

\CodeIgniter\Router\RouteCollectionInterface

reverseRoute()

reverseRoute(string  $search, array  ...$params) : string|false

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

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

string $search
array $params variadic

Returns

string|false

isFiltered()

isFiltered(string  $search) : boolean

Checks a route (using the "from") to see if it's filtered or not.

Parameters

string $search

Returns

boolean

getFilterForRoute()

getFilterForRoute(string  $search) : string

Returns the filter that should be applied for a single route, along with any parameters it might have. Parameters are found by splitting the parameter name on a colon to separate the filter name from the parameter list, and the splitting the result on commas. So:

'role:admin,manager'

has a filter of "role", with parameters of ['admin', 'manager'].

Parameters

string $search

Returns

string

resetRoutes()

resetRoutes() 

Reset the routes, so that a FeatureTestCase can provide the explicit ones needed for it.

discoverRoutes()

discoverRoutes() 

Will attempt to discover any additional routes, either through the local PSR4 namespaces, or through selected Composer packages.

fillRouteParams()

fillRouteParams(string  $from, array|null  $params = null) : string

Given a

Parameters

string $from
array|null $params

Returns

string

create()

create(string  $verb, string  $from, string|array  $to, array  $options = null) 

Does the heavy lifting of creating an actual route. You must specify the request method(s) that this route will work for. They can be separated by a pipe character "|" if there is more than one.

Parameters

string $verb
string $from
string|array $to
array $options

checkSubdomains()

checkSubdomains(mixed  $subdomains) : boolean

Compares the subdomain(s) passed in against the current subdomain on this page request.

Parameters

mixed $subdomains

Returns

boolean

determineCurrentSubdomain()

determineCurrentSubdomain() 

Examines the HTTP_HOST to get a best match for the subdomain. It won't be perfect, but should work for our needs.

It's especially not perfect since it's possible to register a domain with a period (.) as part of the domain name.