router()
Creates a micro-router and executes the routing action immediately
Parameters
Name | Type | Default |
---|---|---|
$path | string |null |
null |
$method | string |
'GET' |
$routes | array |
[ ] |
$callback | Closure |null |
null |
Return type
mixed
|null
Example
The router()
helper takes a set of routes and request data and directly executes the matching routing action.
This helper is great to build your own custom router. This could be done in the config or in a custom script.
Although the example above could of course also simply be solved with more route definitions, it's sometimes really useful to implement such a nested router.
You can also use it for any kind of logic that depends on path matching with regex.