Router
extends KBase
in package
Router class for website page routing.
Tags
Table of Contents
- $cfg : object
- Config class instance.
- $request : Request
- Server request class instance.
- $rules : array<string|int, mixed>
- Rules for website page routing.
- init() : static
- Initialize the Router.
- parseRoutes() : array<string|int, mixed>
- Parse the path and return it as a query string.
Properties
$cfg
Config class instance.
protected
static object
$cfg
$request
Server request class instance.
protected
static Request
$request
$rules
Rules for website page routing.
protected
array<string|int, mixed>
$rules
= [
// index.php/module/model/folder/_dir/_method
'/^[a-z0-9]+\.php\/([a-z]+)\/(model)(\/([\/a-z0-9_]+)\/([a-z0-9_]+))?$/i' => ['module', '_mvc', '', '_dir', '_method'],
// index/model/_dir
'/([a-z]+)\/(model|controller|view)\/([a-z0-9_]+)/i' => ['module', '_mvc', '_dir'],
// module/alias
'/^([a-z]+)\/(.*)$/' => ['module', 'alias'],
// module, module.php
'/^([a-z0-9_]+)(\.php)?$/' => ['module'],
// alias
'/^(.*)$/' => ['alias'],
]
Methods
init()
Initialize the Router.
public
init(string $className) : static
Parameters
- $className : string
-
The class to receive values from the Router.
Tags
Return values
static —parseRoutes()
Parse the path and return it as a query string.
public
parseRoutes(string $path, array<string|int, mixed> $modules) : array<string|int, mixed>
Parameters
- $path : string
-
The path, e.g., /a/b/c.html
- $modules : array<string|int, mixed>
-
Query string