cphalcon: [BUG] Action forwarding is not working in 'dispatch:beforeException'.
Hi all,
It is related to this: http://docs.phalconphp.com/en/latest/reference/dispatching.html#handling-not-found-exceptions. Whenever an exception is thrown, action forwarding to Error controller does not work and results in a blank page.
Steps to repro:
- Check out Phalcon’s “INVO” example.
- Create ErrorController.php:
class ErrorController extends ControllerBase
{
public function indexAction()
{
error_log('Error Controller');
}
}
- Create view script “error/index.volt” with a message “KABOOM!”
- Edit /index.php and use the following code:
/**
* We register the events manager
*/
$di->set('dispatcher', function() use ($di) {
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch:beforeDispatchLoop', function(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) {
throw new \Exception('Just because');
});
$eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) use (&$di) {
error_log('dispatch:beforeException');
$dispatcher->forward(
array(
'controller' => 'error',
'action' => 'index',
'error' => $exception
)
);
return false;
});
$security = new Security($di);
/**
* We listen for events in the dispatcher using the Security plugin
*/
$eventsManager->attach('dispatch', $security);
$dispatcher = new Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
Exception “Just because” is thrown and caught in ‘dispatch:beforeException’. However, forwarding to /error/index does not work. Execution terminates immediately after “return false”. I am using PHPEd debugger to trace it.
Also,
Can Phalcon guys explain the following cryptic sentence from the docs:
Only exceptions produced by the dispatcher and exceptions produced in the executed action are notified in the ‘beforeException’ events. Exceptions produced in listeners or controller events are redirected to the latest try/catch.
What does that really mean??
Thanks!
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 26 (23 by maintainers)
I think this issue is already opened somewhere. @virgofx was planning to fix this.
The issue is super obvious - https://github.com/phalcon/cphalcon/blob/master/phalcon/dispatcher.zep#L343
There is exception is catched, but actual dispatch loop where forward could work is happening here https://github.com/phalcon/cphalcon/blob/master/phalcon/dispatcher.zep#L390
This is why you can’t forward from beforeException.