We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Response set within dispatch:beforeException gets wiped

Steps to reproduce:

  1. Throw an exception.
  2. dispatch:beforeException -> handle exception, response->setContent(), return false, now the app flow returns to application.zep.
  3. application.zep -> now possibleResponse === NULL and implicitView === true (default).
  4. application.zep -> possibleResponse was not false and was not a Response object, so eventually this gets executed on line 399 response->setContent(view->getContent()) and wipes out any reponse I have previously set.
  5. App returns to index.php ->
    $response = $application->handle();

    the Response is now empty, because it was cleared in step 4.

Perhaps handle returning a response object from dispatch:beforeException? Because currently Phalcon is clearing a response when it IMO shouldn't.

Unless there is a way to circumvent this behavior? The only one I can think of would be to $application->useImplicitView(false), but I don't want to do that since I use views in my app.

your thinking is wrong.

When attaching the event to your callback, you have the exception parameter.

If your exeception code is 8 then it is a notice you just have to do nothing. in the other case then the route does not exist.You don't have to put anything in the response. You can put the exception details in a session variable then return false; You can also use syslog to log the exception.

Then the exception will be thrown in your view because it don't know what to render and then you use a try catch inside iyour custom view service to expose what you want to display by rendering another controller/action using: