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

how to add custom route

My Custom Routes are

$defaultModule = ucfirst($registry->defaultModule);
$router = new \Phalcon\Mvc\Router\Annotations(true);
$router->removeExtraSlashes(true);
$router->setDefaultModule(ucfirst($defaultModule));
$router->setDefaultNamespace(ucfirst($defaultModule).'\Controllers');
            $router->setDefaultController("index");
            $router->setDefaultAction("index");

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

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

$router->add('/:controller/:action', [
    'controller' => 1,
    'action' => 2
]);

$router->add('/:controller', [
    'controller' => 1
 ]);

$router->add('/', [
    'module' => ucfirst($defaultModule),
    'controller' => 'index',
    'action' => 'index'
]);

$router->notFound(array(
    'module' => $defaultModule,
    'namespace' => ucfirst($defaultModule).'\Controllers',
    'controller' => 'Error',
    'action' => 'show404'
));

when I make a request to Module2/Controller/Action redirect to no page found After analyse try to print the eventmanager and saw namespace of default module i.e Module1/Controllers

How to resolve it ??



58.4k

Hey

You can see here