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

Should beforeExecuteRoute prevent view from rendering

From the sparse documentation I have understood that beforeExecuteRoute prevents action being executed, that works. However I would expect that the associated view won't be rendered too, though the foollowing code will result into rendering it, why? What is the point of it?

<?php

use Phalcon\Mvc\Dispatcher,
    Phalcon\Mvc\View;

class TestController extends \Phalcon\Mvc\Controller {

    public function beforeExecuteRoute(Dispatcher $dispatcher)
    {
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
        // refuse non-Ajax requests
        if (!$this->request->isAjax()) {
            bdump('prevented');
            return false;
        }
        return true;
    }

    public function fooAction()
    {
        bdump('foo action');
    }
}

It's automatic view render from Phalcom\Mvc\Application. You just need to disable it.

    $application = new Application($di);

    $application->useImplicitView(false);