Menu

## Router extends KBase
in package

Router.php : 18

Router class for website page routing.

##### Tags

see
  https://www.kotchasan.com/

### 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

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

#### $rules

Router.php : 25

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()

Router.php : 45

Initialize the Router.

`public init(string $className) : static`

##### Parameters

$className : string

  The class to receive values from the Router.

##### Tags

throws
  InvalidArgumentException

  If the target class is not found.

##### Return values

static —

#### parseRoutes()

Router.php : 97

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

##### Tags

assert

  ('/print.php/css/view/index', []) [==] array( '_mvc' => 'view', '_dir' => 'index', 'module' => 'css')

assert

  ('/index/model/updateprofile.php', []) [==] array( '_mvc' => 'model', '_dir' => 'updateprofile', 'module' => 'index')

assert

  ('/index.php/alias/model/admin/settings/save', []) [==] array('module' => 'alias', '_mvc' => 'model', '_dir' => 'admin/settings', '_method' => 'save')

assert

  ('/css/view/index.php', []) [==] array('module' => 'css', '_mvc' => 'view', '_dir' => 'index')

assert

  ('/module/ทดสอบ.html', []) [==] array('alias' => 'ทดสอบ', 'module' => 'module')

assert

  ('/module.html', []) [==] array('module' => 'module')

assert

  ('/ทดสอบ.html', []) [==] array('alias' => 'ทดสอบ')

assert

  ('/ทดสอบ.html', array('module' => 'test')) [==] array('alias' => 'ทดสอบ', 'module' => 'test')

assert

  ('/index.php', array('_action' => 'one')) [==] array('_action' => 'one')

assert

  ('/admin_index.php', array('_action' => 'one')) [==] array('_action' => 'one', 'module' => 'admin_index')

##### Return values

array<string|int, mixed> —

## Search results