Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



30.4k
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

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