I have a component configured as a beforeDispatch
listener. This component checks if a form was POSTed, then checks that the CSRF token was properly sent. If not, it is supposed to forward to a special CSRF notification page. I specifically want to do a forward and not a redirect so that users have the option of reporting which page they visited.
Here is my code:
public function beforeDispatch(\Phalcon\Events\Event $Event,\Phalcon\Mvc\Dispatcher $Dispatcher){
if($this->request->isPost()){
if(!$this->checkToken()){
echo 'before';
$Dispatcher->forward(['controller'=>'index','action'=>'csrf']);
echo 'after';
exit();
}
}
}
All I get is a page that displays "beforeafter". If I take those echo
s out, I just get a blank page. I can visit /index/csrf/
manually and it displays the page I want.
Why is the request not getting forwarded? Is this out of the dispatch loop?