Oki probably found a solution:
$di->setShared('appDispatcher', $di->get('dispatcher'));
in AbstractController i declare request function which is originally defined here: https://github.com/phalcon/mvc/blob/master/hmvc/public/index.php#L49
public function request($location)
{
/** @var Dispatcher $dispatcher */
$dispatcher = clone $this->getDI()->get('appDispatcher');
if (isset($location['namespace'])) {
$dispatcher->setDefaultNamespace($location['namespace'] . '\\Controllers');
}
if (isset($location['controller'])) {
$dispatcher->setControllerName($location['controller']);
} else {
$dispatcher->setControllerName('index');
}
if (isset($location['action'])) {
$dispatcher->setActionName($location['action']);
} else {
$dispatcher->setActionName('index');
}
if (isset($location['params'])) {
if (is_array($location['params'])) {
$dispatcher->setParams($location['params']);
} else {
$dispatcher->setParams((array)$location['params']);
}
} else {
$dispatcher->setParams(array('multiRequest' => true));
}
$dispatcher->dispatch();
$response = $dispatcher->getReturnedValue();
if ($response instanceof ResponseInterface) {
return $response->getContent();
}
return $response;
}
afterExecuteRoute will simply handle multiRequest by forwarded param
public function afterExecuteRoute(\Phalcon\Mvc\Dispatcher $dispatcher)
{
$params = $dispatcher->getParams();
$data = $dispatcher->getReturnedValue();
if (is_array($data)) {
$data = json_encode($data);
}
if (!isset($params['multiRequest'])) {
$this->view->disable();
$this->response->setHeader('Cache-Control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
$this->response->setExpires(new \DateTime('Mon, 26 Jul 1997 05:00:00 GMT'));
$this->response->setContentType('application/json', 'UTF-8');
$this->response->setContent($data);
$this->response->send();
}
}
and finally multirequest action:
$router = $this->router;
$router->handle($requestParams);
$r = $this->request(array(
'namespace' => $router->getModuleName(),
'controller' => $router->getControllerName(),
'action' => $router->getActionName()
));