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 execute controller's action or forward/redirect to it outside controller?

I have such application cycle:

try {
    /////// Preparing something for app
   $response = $application->handle($_SERVER['REQUEST_URI']);
   $response->send();
} catch(Exception $e) {
   //////// Here i need to execute some controller's action
}

I tried to redirect or forward dispatcher but i don't know how to start that operation.

However, i also use dispatcher:beforeException event but i'm not sure i will catch all possible exceptions.



32.2k
Accepted
answer

dispatcher:beforeException I think is the right way. Now a not fancy way

try {
    /////// Preparing something for app
   $response = $application->handle($_SERVER['REQUEST_URI']);
   $response->send();
} catch(Exception $e) {
   $application->handle('/a/not/fancy/url');
}

Good luck



2.0k

Looks like a kludge, but works as needed, thank you.