Try to do the same in beforeExecuteRoute(). Phalcon is initialize()designed, as its name is, to initialize things. You can send there using the dispatcher, but do not have to redirect.
. " ?" , false, .
- , beforeExecuteRoute() , , .
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{
if (!$this->request->isAjax()) {
return $this->response->redirect('error/show404');
}
}