I have a small method where I connect the NC links to each module. This method connects all CNC links to the main page of the site, to a single entry point. Here he is:

<?php /* * Получаю роутеры из модулей. */ public function getRoutes() { if($this->counting() > 0) { $this->list = $this->db->query("SELECT `module`, `ru_name`, `version`, `author_e-mail` FROM `modules` ORDER BY `module`"); while ($module = $this->list->fetch()) { if(file_exists(H. $this->module_directory.'/'.$module['module'].'/system/routes.php')) { require H. $this->module_directory.'/'.$module['module'].'/system/routes.php'; } else { echo 'Роутеры в модуле "'.$module['ru_name'].'" не найдены. Обратитесь за технической поддержкой к разработчику даного модуля - '.$module['author_e-mail']; //$this->db->close(); } } } r($this->list); } ?> 

And I call him like this:

  <?php /* * Инициализация класса Module */ $module = new Module(Vars::get('settings/MYSQL')); /* * Подключение */ $router = new AltoRouter(); $module->getRoutes(); // match current request $match = $router->match(); if($match['target']) { require H. $match['target']; } else { Redirect::go(); } 

At the output I get the error:

Fatal error: Call to a member function map () on null in D: \ OpenServer \ domains \ cms \ module \ user \ system \ routes.php on line 4

Routes.php file:

 <?php //Пользователь $router->map('GET','/profile/[i:id]', '/module/user/profile.php', 'profile'); $router->map('GET|POST','/profile/edit', '/module/user/edit.php', 'profile_edit'); 

In theory, this file should be connected to the root of the site, and the AltoRouter class should pick up this code ... but this does not happen.

  • Where is $ router defined in routes.php? He throws a mistake about it - $ router is null there. You probably need to include or require_once on routes.php from the main file. - Daniel Protopopov
  • On each module to create an instance of the class router? It seems to be embedded in the main file, where $ router is already defined - No0k
  • In Yii1 (and in Yii2, probably) each module has a routing mechanism in it; you can have a root one - but it will be, as you said, in one file. Who is more convenient. - Daniel Protopopov

0