Router setDefaults can't work?

In Index i had define:

<?php ......

$di->setShared('router', function() {

$router = new \Phalcon\Mvc\Router();

$router->add('/:module/:controller/:action/:params', [
    'module'      => 1,
    'controller'  => 2,
    'action'      => 3,
    'params'      => 4,
]);
$router->setDefaultAction('index');
return $router;

});

..............

$application = new \Phalcon\Mvc\Application($di);

$application->registerModules([

'frontend' => ['path' => APPLICATION_ROOT . '/application/modules/frontend/Module.php'],

'admin' => ['path' => APPLICATION_ROOT . '/application/modules/admin/Module.php'],

'task' => ['path' => APPLICATION_ROOT . '/application/modules/task/Module.php'],

'tmp' => ['path' => APPLICATION_ROOT . '/application/modules/tmp/Module.php'],

'api' => ['path' => APPLICATION_ROOT . '/application/modules/api/Module.php'],

]);

$application->useImplicitView(true);

$application->setDefaultModule("frontend");

.....

when i visit http://xxx.com/frontend/passport/index ,it's work good, but when visit http://xxx.com/frontend/passport/ ,It's say:

Modules\Frontend\Controllers\FrontendController handler class cannot be loaded

Hi, try this:

                 $router->setDefaults(array(
                  'controller' => 'YourDefaultController',
                  'action' => 'index'
                  ));


1.1k

@PollDeveloper

Can't work too. :(

edited Jan '17

You'll have to register each level of path:

$router->add('/:module/:controller/:action/:params', [
    'module'      => 1,
    'controller'  => 2,
    'action'      => 3,
    'params'      => 4,
]);
$router->add('/:module/:controller', [
    'module'      => 1,
    'controller'  => 2,
    'action' => 'index', // this line is not necessary
]);
$router->add('/:module', [
    'module'      => 1,
    'controller'  => 'index', // this line is not necessary
    'action' => 'index', // this line s not necessary
]);


1.1k

@Ljos Bencz

Thank you.