We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Mvc\Router()

<?php
$router->add("/admin/([a-zA-Z0-9_-]+)[/]?([a-zA-Z0-9_]+)?[/]?(/.*)*", array(
        'namespace' => 'App\Controllers\Admin',
        'controller' => 1,
        'action' => 2,
        'params' => 3
));

//when the action pattern matches is empty why the action value is 2, not the 'index' on linux


19.2k

Because it reads

'action' => 2,

as a default action. Add that route:

$router->add("/admin/:controller", array(
    'namespace' => 'App\Controllers\Admin',
    'controller' => 1,
    'action' => 'index'
));

Also, your route is the same as

$router->add("/admin/:controller/:action/:params", array(
    'namespace' => 'App\Controllers\Admin',
    'controller' => 1,
    'action' => 2,
    'params' => 3
));

Why not use the more simple syntax?