Documentation

Router
in package

URL Router

Used in October CMS for managing page routes.

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$defaultValue  : string
$matchedRouteRule  : Rule
$parameters  : array<string|int, mixed>
$routeMap  : array<string|int, mixed>
getParameters()  : array<string|int, mixed>
Returns a list of parameters specified in the requested page URL.
getRouteMap()  : array<string|int, mixed>
Returns the active list of router rule objects
match()  : array<string|int, mixed>
Match given URL string
matchedRoute()  : Rule
Returns the matched route rule name.
reset()  : $this
Clears all existing routes
route()  : mixed
Registers a new route rule
sortRules()  : void
Sorts all the routing rules by static segments, then dynamic
url()  : string
Builds a URL together by matching route name and supplied parameters
urlFromPattern()  : string
Builds a URL together by matching route pattern and supplied parameters

Properties

$defaultValue

public static string $defaultValue = 'default'

Value to use when a required parameter is not specified

$matchedRouteRule

protected Rule $matchedRouteRule

A referred to the matched router rule

$parameters

protected array<string|int, mixed> $parameters = []

A list of parameters names and values extracted from the URL pattern and URL string

$routeMap

protected array<string|int, mixed> $routeMap = []

A list of specified routes

Methods

getParameters()

Returns a list of parameters specified in the requested page URL.

public getParameters() : array<string|int, mixed>

For example, if the URL pattern was /blog/post/:id and the actual URL was /blog/post/10, the $parameters['id'] element would be 10.

Return values
array<string|int, mixed>

An associative array with keys matching the parameter names specified in the URL pattern and values matching the corresponding segments of the actual requested URL.

getRouteMap()

Returns the active list of router rule objects

public getRouteMap() : array<string|int, mixed>
Return values
array<string|int, mixed>

An associative array with keys matching the route rule names and values matching the router rule object.

match()

Match given URL string

public match(string $url) : array<string|int, mixed>
Parameters
$url : string

Request URL to match for

Return values
array<string|int, mixed>

$parameters A reference to a PHP array variable to return the parameter list fetched from URL.

matchedRoute()

Returns the matched route rule name.

public matchedRoute() : Rule
Return values
Rule

The matched rule object.

reset()

Clears all existing routes

public reset() : $this
Return values
$this

route()

Registers a new route rule

public route(mixed $name, mixed $route) : mixed
Parameters
$name : mixed
$route : mixed
Return values
mixed

sortRules()

Sorts all the routing rules by static segments, then dynamic

public sortRules() : void
Return values
void

url()

Builds a URL together by matching route name and supplied parameters

public url(string $name[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
$name : string

Name of the route previously defined.

$parameters : array<string|int, mixed> = []

Parameter name => value items to fill in for given route.

Return values
string

Full matched URL as string with given values put in place of named parameters

urlFromPattern()

Builds a URL together by matching route pattern and supplied parameters

public urlFromPattern(string $pattern[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
$pattern : string

Route pattern string, eg: /path/to/something/:parameter

$parameters : array<string|int, mixed> = []

Parameter name => value items to fill in for given route.

Return values
string

Full matched URL as string with given values put in place of named parameters

Search results