Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Problem with routes in multi modules app

I have multi models application. In my Bootrstrap I set up to DI Roter class

$this->getDi()->set('router', function () {

    $router =  new \Phalcon\Mvc\Router(false);
    $router->add("/:module/:controller/:action/:params", array(
        "module" => 1, 
        "controller" => 2,
        "action" => 3,
        "params" => 4,

    $router->add('/', array(
        'namespace' => 'Frontend\Controllers',
        'module' => 'frontend',
        'controller' => 'index',
        'action' => 'test'

    return $router;
}, true);

In my module in Module.php file I add additional routes:

$router = $di->get('router'); 
$router->add("/test", array(
        'module' => 'frontend',
        'controller' => 'index',
        'action' => 'test'

and unfortunately no routes which were added to Module.php are working.

edited Aug '14

Adding routes to Module.php would not work that way. Module.php is executed after parsing the current route in the router, so you will be adding routes at a stage were the module is already processed.

  • Mvc\Router identifiies module, controller and action to be executed based on current URI
  • Mvc\Router passes this parameters to Mvc\Application
  • Mvc\Application loads Module.php and executes registerAutoloader/registerServices on there (Mvc\Router already did its job!)


Thanks for quick answer.