This is my router
<?php
/*============================= API ====================================*/
$router->add("/api", array(
'module' => 'api'
))->setName('api');
$apiRoutes = [
'/' => 'Index',
'/users' => 'Users'
];
foreach($apiRoutes as $route => $className){
$router->addModuleResource('api', 'MyPackage\API\Controllers\\' . $className, '/api' . $route);
}
/*============================= Pub ====================================*/
$router->add('/confirm/{code}/{email}', array(
'controller' => 'user_control',
'action' => 'confirmEmail'
));
$router->add('/signup', array(
'controller' => 'session',
'action' => 'signup'
))->setName('signup');
$router->add('/reset-password/{code}/{email}', array(
'controller' => 'user_control',
'action' => 'resetPassword'
));
/*============================= Admin ====================================*/
$router->add("/admin", array(
'module' => 'admin'
));
$router->add(
"/admin/:controller",
array(
'module' => 'admin',
"controller" => 1
)
);
$router->add(
"/admin/:controller/:action/",
array(
'module' => 'admin',
"controller" => 1,
"action" => 2
)
);
$router->add(
"/admin/:controller/:action/:params",
array(
'module' => 'admin',
"controller" => 1,
"action" => 2,
"params" => 3,
)
);
In every module I have
$di['dispatcher'] = function() {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) {
//Handle 404 exceptions
if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'show404'
));
return false;
}
...
This works for Pub and Admin module. Is any way for doing this in API module? It is critical issue for me