We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

View is still called on controller interrupt event

Hello! I have a basic Phalcon project. For personal reasons i don't want to use the ACL.

But whenever i want to INTERRUPT the execution of the controller (for example to use the redirect function from response) the layout is still called. This represents a problem as if the view uses a variable the script will return broken layout with 500 error.

In my case, the DashboardController have a function beforeExecuteRoute that executes $this->response->redirect('login'); and returns false if user is not logged. But as the Dashboard/index template uses a variable, instead of redirecting, i receive a 500 error and it logs on apache error log " PHP Fatal error: Call to a member function getAction() on a non-object in /srv/www/htdocs/var/cache/template/compiled/%%srv%%www%%htdocs%%app%%template%%account%%forgotpassword.volt.php "



11.2k

So, am i using the view/events not in the right way ?



98.9k
Accepted
answer

Try adding

$this->view->disable();

before return false;



11.2k

Thank you @Phalcon, that solved it and is cleaner than my first approach :)