Пример #1
0
 /**
  * Initiates router
  *
  * Creates generic routes.
  * Adds custom route matchtypes.
  *
  * @return void
  */
 private function initRouter()
 {
     $this->di->mapService('core.router', '\\Core\\Router\\Router');
     $this->router = $this->di->get('core.router');
     $this->router->setBaseUrl(BASEURL);
     $this->router->setParametersToTarget(['app', 'controller', 'action']);
     $this->router->addMatchTypes(['mvc' => '[A-Za-z0-9_]++']);
     // Generic routes
     $routes = ['index' => ['route' => '/[mvc:app]/[mvc:controller]', 'target' => ['action' => 'index']], 'action' => ['route' => '/[mvc:app]/[mvc:controller]/[mvc:action]'], 'id' => ['route' => '/[mvc:app]/[mvc:controller]/[i:id]?/[mvc:action]'], 'child' => ['route' => '/[mvc:app]/[mvc:controller]/[i:id]?/[mvc:action]/of/[i:id_parent]']];
     foreach ($routes as $name => $route) {
         $this->router->map($route['method'] ?? 'GET|POST', $route['route'], $route['target'] ?? [], 'generic.' . $name);
     }
 }