RouteCollection
in package
implements
RouteCollectionInterface
Tags
Table of Contents
Interfaces
- RouteCollectionInterface
- Interface RouteCollectionInterface
Properties
- $defaultHTTPMethods : array<int, string>
- The default list of HTTP methods (and CLI for command line usage) that is allowed if no other method is provided.
- $autoRoute : bool
- Whether to match URI against Controllers when it doesn't match defined routes.
- $currentOptions : array<string|int, mixed>|null
- Stores copy of current options being applied during creation.
- $currentSubdomain : string|null
- The current subdomain.
- $defaultController : string
- The name of the default controller to use when no other controller is specified.
- $defaultMethod : string
- The name of the default method to use when no other method has been specified.
- $defaultNamespace : string
- The namespace to be added to any Controllers.
- $defaultPlaceholder : string
- The placeholder used when routing 'resources' when no other placeholder has been specified.
- $didDiscover : bool
- A little performance booster.
- $fileLocator : FileLocatorInterface
- Handle to the file locator to use.
- $group : string|null
- The name of the current group, if any.
- $HTTPVerb : string
- The current method that the script is being called by.
- $moduleConfig : Modules
- Handle to the modules config.
- $override404 : callable(string): Array|string
- A callable that will be shown when the route cannot be matched.
- $placeholders : array<string, string>
- Defined placeholders that can be used within the
- $prioritize : bool
- Flag for sorting routes by priority.
- $prioritizeDetected : bool
- Route priority detection flag.
- $routeFiles : array<string|int, mixed>
- An array of files that would contain route definitions.
- $routes : array<string|int, mixed>
- An array of all routes and their mappings.
- $routesNames : array<string|int, mixed>
- Array of routes names
- $routesOptions : array<string|int, mixed>
- Array of routes options
- $translateURIDashes : bool
- Whether to convert dashes to underscores in URI.
- $useSupportedLocalesOnly : bool
- Flag to limit or not the routes with {locale} placeholder to App::$supportedLocales
- $httpHost : string|null
- The current hostname from $_SERVER['HTTP_HOST']
Methods
- __construct() : mixed
- Constructor
- 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.
- addRedirect() : RouteCollection
- Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes.
- cli() : RouteCollectionInterface
- Specifies a route that is only available to command-line requests.
- delete() : RouteCollectionInterface
- Specifies a route that is only available to DELETE requests.
- environment() : RouteCollectionInterface
- Limits the routes to a specified ENVIRONMENT or they won't run.
- get() : RouteCollectionInterface
- Specifies a route that is only available to GET requests.
- 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.
- getDefaultNamespace() : string
- Returns the default namespace as set in the Routes config file.
- getFiltersForRoute() : array<int, string>
- Returns the filters 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:
- getHTTPVerb() : string
- Returns the current HTTP Verb being used.
- getRedirectCode() : int
- Grabs the HTTP status code from a redirecting Route.
- getRegisteredControllers() : array<int, string>
- Get all controllers in Route Handlers
- getRoutes() : array<string|int, mixed>
- Returns the raw array of available routes.
- getRoutesOptions() : array<string, int|string>
- Returns one or all routes options
- group() : void
- Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like:
- head() : RouteCollectionInterface
- Specifies a route that is only available to HEAD requests.
- isFiltered() : bool
- Checks a route (using the "from") to see if it's filtered or not.
- isRedirect() : bool
- Determines if the route is a redirecting route.
- loadRoutes() : $this
- Loads main routes file and discover routes.
- map() : RouteCollectionInterface
- A shortcut method to add a number of routes at a single time.
- match() : RouteCollectionInterface
- Specifies a single route to match for multiple HTTP Verbs.
- options() : RouteCollectionInterface
- Specifies a route that is only available to OPTIONS requests.
- patch() : RouteCollectionInterface
- Specifies a route that is only available to PATCH requests.
- post() : RouteCollectionInterface
- Specifies a route that is only available to POST requests.
- presenter() : RouteCollectionInterface
- Creates a collections of HTTP-verb based routes for a presenter controller.
- put() : RouteCollectionInterface
- Specifies a route that is only available to PUT requests.
- resetRoutes() : void
- Reset the routes, so that a test case can provide the explicit ones needed for it.
- resource() : RouteCollectionInterface
- Creates a collections of HTTP-verb based routes for a controller.
- reverseRoute() : false|string
- Attempts to look up a route based on its 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.
- setDefaultConstraint() : RouteCollectionInterface
- Sets the default constraint to be used in the system. Typically for use with the 'resource' method.
- 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.
- setHTTPVerb() : $this
- Sets the current HTTP verb.
- setPrioritize() : $this
- Enable or Disable sorting routes by priority
- 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
- useSupportedLocalesOnly() : self
- Set The flag that limit or not the routes with {locale} placeholder to App::$supportedLocales
- view() : RouteCollectionInterface
- Specifies a route that will only display a view.
- buildReverseRoute() : string
- Builds reverse route
- create() : void
- 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.
- discoverRoutes() : void
- Will attempt to discover any additional routes, either through the local PSR4 namespaces, or through selected Composer packages.
- fillRouteParams() : string
- Given a
-
loadRoutesOptions()
: array<string, array{filter?: string|list
, namespace?: string, hostname?: string, subdomain?: string, offset?: int, priority?: int, as?: string, redirect?: int}> - Load routes options based on verb
- localizeRoute() : string
- Replaces the {locale} tag with the current application locale
- checkHostname() : bool
- Compares the hostname passed in against the current hostname on this page request.
- checkSubdomains() : bool
- Compares the subdomain(s) passed in against the current subdomain on this page request.
- determineCurrentSubdomain() : false|string
- Examines the HTTP_HOST to get the best match for the subdomain. It won't be perfect, but should work for our needs.
- getControllerName() : string|null
- getMethodParams() : string
- Returns the method param string like `/$1/$2` for placeholders
- processArrayCallableSyntax() : string
- replaceLocale() : string
- Replaces the {locale} tag with the locale
Properties
$defaultHTTPMethods
The default list of HTTP methods (and CLI for command line usage) that is allowed if no other method is provided.
public
array<int, string>
$defaultHTTPMethods
= \CodeIgniter\Router\Router::HTTP_METHODS
$autoRoute
Whether to match URI against Controllers when it doesn't match defined routes.
protected
bool
$autoRoute
= false
Not used here. Pass-thru value for Router class.
$currentOptions
Stores copy of current options being applied during creation.
protected
array<string|int, mixed>|null
$currentOptions
$currentSubdomain
The current subdomain.
protected
string|null
$currentSubdomain
$defaultController
The name of the default controller to use when no other controller is specified.
protected
string
$defaultController
= 'Home'
Not used here. Pass-thru value for Router class.
$defaultMethod
The name of the default method to use when no other method has been specified.
protected
string
$defaultMethod
= 'index'
Not used here. Pass-thru value for Router class.
$defaultNamespace
The namespace to be added to any Controllers.
protected
string
$defaultNamespace
= '\\'
Defaults to the global namespaces ().
This must have a trailing backslash ().
$defaultPlaceholder
The placeholder used when routing 'resources' when no other placeholder has been specified.
protected
string
$defaultPlaceholder
= 'any'
$didDiscover
A little performance booster.
protected
bool
$didDiscover
= false
$fileLocator
Handle to the file locator to use.
protected
FileLocatorInterface
$fileLocator
$group
The name of the current group, if any.
protected
string|null
$group
$HTTPVerb
The current method that the script is being called by.
protected
string
$HTTPVerb
= '*'
HTTP verb like GET
,POST
or *
or CLI
$moduleConfig
Handle to the modules config.
protected
Modules
$moduleConfig
$override404
A callable that will be shown when the route cannot be matched.
protected
callable(string): Array|string
$override404
$placeholders
Defined placeholders that can be used within the
protected
array<string, string>
$placeholders
= ['any' => '.*', 'segment' => '[^/]+', 'alphanum' => '[a-zA-Z0-9]+', 'num' => '[0-9]+', 'alpha' => '[a-zA-Z]+', 'hash' => '[^/]+']
$prioritize
Flag for sorting routes by priority.
protected
bool
$prioritize
= false
$prioritizeDetected
Route priority detection flag.
protected
bool
$prioritizeDetected
= false
$routeFiles
An array of files that would contain route definitions.
protected
array<string|int, mixed>
$routeFiles
= []
$routes
An array of all routes and their mappings.
protected
array<string|int, mixed>
$routes
= ['*' => [], \CodeIgniter\HTTP\Method::OPTIONS => [], \CodeIgniter\HTTP\Method::GET => [], \CodeIgniter\HTTP\Method::HEAD => [], \CodeIgniter\HTTP\Method::POST => [], \CodeIgniter\HTTP\Method::PATCH => [], \CodeIgniter\HTTP\Method::PUT => [], \CodeIgniter\HTTP\Method::DELETE => [], \CodeIgniter\HTTP\Method::TRACE => [], \CodeIgniter\HTTP\Method::CONNECT => [], 'CLI' => []]
[ verb => [ routeKey(regex) => [ 'name' => routeName 'handler' => handler, 'from' => from, ], ], // redirect route '*' => [ routeKey(regex)(from) => [ 'name' => routeName 'handler' => [routeKey(regex)(to) => handler], 'from' => from, 'redirect' => statusCode, ], ], ]
$routesNames
Array of routes names
protected
array<string|int, mixed>
$routesNames
= ['*' => [], \CodeIgniter\HTTP\Method::OPTIONS => [], \CodeIgniter\HTTP\Method::GET => [], \CodeIgniter\HTTP\Method::HEAD => [], \CodeIgniter\HTTP\Method::POST => [], \CodeIgniter\HTTP\Method::PATCH => [], \CodeIgniter\HTTP\Method::PUT => [], \CodeIgniter\HTTP\Method::DELETE => [], \CodeIgniter\HTTP\Method::TRACE => [], \CodeIgniter\HTTP\Method::CONNECT => [], 'CLI' => []]
[ verb => [ routeName => routeKey(regex) ], ]
$routesOptions
Array of routes options
protected
array<string|int, mixed>
$routesOptions
= []
[ verb => [ routeKey(regex) => [ key => value, ] ], ]
$translateURIDashes
Whether to convert dashes to underscores in URI.
protected
bool
$translateURIDashes
= false
Not used here. Pass-thru value for Router class.
$useSupportedLocalesOnly
Flag to limit or not the routes with {locale} placeholder to App::$supportedLocales
protected
bool
$useSupportedLocalesOnly
= false
$httpHost
The current hostname from $_SERVER['HTTP_HOST']
private
string|null
$httpHost
= null
Methods
__construct()
Constructor
public
__construct(FileLocatorInterface $locator, Modules $moduleConfig, Routing $routing) : mixed
Parameters
- $locator : FileLocatorInterface
- $moduleConfig : Modules
- $routing : Routing
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
Example: $routes->add('news', 'Posts::index');
Parameters
- $from : string
-
The route path (with placeholders or regex)
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $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
RouteCollectionInterfaceaddRedirect()
Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes.
public
addRedirect(string $from, string $to[, int $status = 302 ]) : RouteCollection
Parameters
- $from : string
-
The pattern to match against
- $to : string
-
Either a route name or a URI to redirect to
- $status : int = 302
-
The HTTP status code that should be returned with this redirect
Return values
RouteCollectioncli()
Specifies a route that is only available to command-line requests.
public
cli(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacedelete()
Specifies a route that is only available to DELETE requests.
public
delete(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfaceenvironment()
Limits the routes to a specified ENVIRONMENT or they won't run.
public
environment(string $env, callable(RouteCollection): void $callback) : RouteCollectionInterface
Parameters
- $env : string
- $callback : callable(RouteCollection): void
Return values
RouteCollectionInterfaceget()
Specifies a route that is only available to GET requests.
public
get(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
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
stringgetDefaultNamespace()
Returns the default namespace as set in the Routes config file.
public
getDefaultNamespace() : string
Return values
stringgetFiltersForRoute()
Returns the filters 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:
public
getFiltersForRoute(string $search[, string|null $verb = null ]) : array<int, string>
'role:admin,manager'
has a filter of "role", with parameters of ['admin', 'manager'].
Parameters
- $search : string
-
routeKey
- $verb : string|null = null
-
HTTP verb like
GET
,POST
or*
orCLI
.
Return values
array<int, string> —filter_name or filter_name:arguments like 'role:admin,manager'
getHTTPVerb()
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
-
routeKey or route name
Return values
intgetRegisteredControllers()
Get all controllers in Route Handlers
public
getRegisteredControllers([string|null $verb = '*' ]) : array<int, string>
Parameters
- $verb : string|null = '*'
-
HTTP verb like
GET
,POST
or*
orCLI
.'*'
returns all controllers in any verb.
Tags
Return values
array<int, string> —controller name list
getRoutes()
Returns the raw array of available routes.
public
getRoutes([non-empty-string|null $verb = null ][, bool $includeWildcard = true ]) : array<string|int, mixed>
Parameters
- $verb : non-empty-string|null = null
-
HTTP verb like
GET
,POST
or*
orCLI
. - $includeWildcard : bool = true
-
Whether to include '*' routes.
Return values
array<string|int, mixed>getRoutesOptions()
Returns one or all routes options
public
getRoutesOptions([string|null $from = null ][, string|null $verb = null ]) : array<string, int|string>
Parameters
- $from : string|null = null
- $verb : string|null = null
-
HTTP verb like
GET
,POST
or*
orCLI
.
Return values
array<string, int|string> —[key => value]
group()
Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like:
public
group(string $name, array<string|int, mixed>|callable ...$params) : void
Example: // Creates route: admin/users $route->group('admin', function() { $route->resource('users'); });
Parameters
- $name : string
-
The name to group/prefix the routes with.
- $params : array<string|int, mixed>|callable
head()
Specifies a route that is only available to HEAD requests.
public
head(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfaceisFiltered()
Checks a route (using the "from") to see if it's filtered or not.
public
isFiltered(string $search[, string|null $verb = null ]) : bool
Parameters
- $search : string
- $verb : string|null = null
-
HTTP verb like
GET
,POST
or*
orCLI
.
Return values
boolisRedirect()
Determines if the route is a redirecting route.
public
isRedirect(string $routeKey) : bool
Parameters
- $routeKey : string
-
routeKey or route name
Return values
boolloadRoutes()
Loads main routes file and discover routes.
public
loadRoutes([string $routesFile = APPPATH . 'Config/Routes.php' ]) : $this
Loads only once unless reset.
Parameters
- $routesFile : string = APPPATH . 'Config/Routes.php'
Return values
$thismap()
A shortcut method to add a number of routes at a single time.
public
map([array<string|int, mixed> $routes = [] ][, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
It does not allow any options to be set on the route, or to define the method used.
Parameters
- $routes : array<string|int, mixed> = []
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacematch()
Specifies a single route to match for multiple HTTP Verbs.
public
match([array<string|int, mixed> $verbs = [] ][, string $from = '' ][, array<string|int, mixed>|callable(mixed...): Array|string $to = '' ][, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Example: $route->match( ['GET', 'POST'], 'users/(:num)', 'users/$1);
Parameters
- $verbs : array<string|int, mixed> = []
- $from : string = ''
- $to : array<string|int, mixed>|callable(mixed...): Array|string = ''
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfaceoptions()
Specifies a route that is only available to OPTIONS requests.
public
options(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacepatch()
Specifies a route that is only available to PATCH requests.
public
patch(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacepost()
Specifies a route that is only available to POST requests.
public
post(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacepresenter()
Creates a collections of HTTP-verb based routes for a presenter controller.
public
presenter(string $name[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
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
- $name : string
-
The name of the controller to route to.
- $options : array<string|int, mixed>|null = null
-
A list of possible ways to customize the routing.
Return values
RouteCollectionInterfaceput()
Specifies a route that is only available to PUT requests.
public
put(string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Parameters
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfaceresetRoutes()
Reset the routes, so that a test case can provide the explicit ones needed for it.
public
resetRoutes() : void
resource()
Creates a collections of HTTP-verb based routes for a controller.
public
resource(string $name[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
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
- $name : string
-
The name of the resource/controller to route to.
- $options : array<string|int, mixed>|null = null
-
A list of possible ways to customize the routing.
Return values
RouteCollectionInterfacereverseRoute()
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
-
Route name or Controller::method
- $params : int|string
-
One or more parameters to be passed to the route. The last parameter allows you to set the locale.
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|string|null $callable = null ]) : RouteCollectionInterface
This setting is passed to the Router class and handled there.
Parameters
- $callable : callable|string|null = null
Return values
RouteCollectionInterfacesetAutoRoute()
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
RouteCollectionInterfacesetDefaultConstraint()
Sets the default constraint to be used in the system. Typically for use with the 'resource' method.
public
setDefaultConstraint(string $placeholder) : RouteCollectionInterface
Parameters
- $placeholder : string
Return values
RouteCollectionInterfacesetDefaultController()
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
RouteCollectionInterfacesetHTTPVerb()
Sets the current HTTP verb.
public
setHTTPVerb(string $verb) : $this
Used primarily for testing.
Parameters
- $verb : string
-
HTTP verb
Return values
$thissetPrioritize()
Enable or Disable sorting routes by priority
public
setPrioritize([bool $enabled = true ]) : $this
Parameters
- $enabled : bool = true
-
The value status
Return values
$thissetTranslateURIDashes()
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
Return values
booluseSupportedLocalesOnly()
Set The flag that limit or not the routes with {locale} placeholder to App::$supportedLocales
public
useSupportedLocalesOnly(bool $useOnly) : self
Parameters
- $useOnly : bool
Return values
selfview()
Specifies a route that will only display a view.
public
view(string $from, string $view[, array<string|int, mixed>|null $options = null ]) : RouteCollectionInterface
Only works for GET requests.
Parameters
- $from : string
- $view : string
- $options : array<string|int, mixed>|null = null
Return values
RouteCollectionInterfacebuildReverseRoute()
Builds reverse route
protected
buildReverseRoute(string $from, array<string|int, mixed> $params) : string
Parameters
- $from : string
- $params : array<string|int, mixed>
-
One or more parameters to be passed to the route. The last parameter allows you to set the locale.
Return values
stringcreate()
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.
protected
create(string $verb, string $from, array<string|int, mixed>|callable(mixed...): Array|string $to[, array<string|int, mixed>|null $options = null ]) : void
Parameters
- $verb : string
- $from : string
- $to : array<string|int, mixed>|callable(mixed...): Array|string
- $options : array<string|int, mixed>|null = null
discoverRoutes()
Will attempt to discover any additional routes, either through the local PSR4 namespaces, or through selected Composer packages.
protected
discoverRoutes() : void
fillRouteParams()
Given a
protected
fillRouteParams(string $from[, array<string|int, mixed>|null $params = null ]) : string
Unused. Now uses buildReverseRoute().
Parameters
- $from : string
- $params : array<string|int, mixed>|null = null
Tags
Return values
stringloadRoutesOptions()
Load routes options based on verb
protected
loadRoutesOptions([string|null $verb = null ]) : array<string, array{filter?: string|list, namespace?: string, hostname?: string, subdomain?: string, offset?: int, priority?: int, as?: string, redirect?: int}>
Parameters
- $verb : string|null = null
Return values
array<string, array{filter?: string|listlocalizeRoute()
Replaces the {locale} tag with the current application locale
protected
localizeRoute(string $route) : string
Unused.
Parameters
- $route : string
Return values
stringcheckHostname()
Compares the hostname passed in against the current hostname on this page request.
private
checkHostname(string $hostname) : bool
Parameters
- $hostname : string
-
Hostname in route options
Return values
boolcheckSubdomains()
Compares the subdomain(s) passed in against the current subdomain on this page request.
private
checkSubdomains(array<int, string>|string $subdomains) : bool
Parameters
- $subdomains : array<int, string>|string
Return values
booldetermineCurrentSubdomain()
Examines the HTTP_HOST to get the best match for the subdomain. It won't be perfect, but should work for our needs.
private
determineCurrentSubdomain() : false|string
It's especially not perfect since it's possible to register a domain with a period (.) as part of the domain name.
Return values
false|string —the subdomain
getControllerName()
private
getControllerName(callable(mixed...): Array|string $handler) : string|null
Parameters
- $handler : callable(mixed...): Array|string
-
Handler
Return values
string|null —Controller classname
getMethodParams()
Returns the method param string like `/$1/$2` for placeholders
private
getMethodParams(string $from) : string
Parameters
- $from : string
Return values
stringprocessArrayCallableSyntax()
private
processArrayCallableSyntax(string $from, array<string|int, mixed> $to) : string
Parameters
- $from : string
- $to : array<string|int, mixed>
Return values
stringreplaceLocale()
Replaces the {locale} tag with the locale
private
replaceLocale(string $route[, string|null $locale = null ]) : string
Parameters
- $route : string
- $locale : string|null = null