Php – How it’s possible to disable rendering layout in case of xmlhttprequest in phalcon framework

controllerlayoutphalconPHPxmlhttprequest

How can be disabled layout rendering?

For a moment i can detect that request is made via jQuery this way:

public function initialize()
{
    if (!$this->request->isAjax()) {
        // disable layout here... how?
    }
}

Could it be done globally?

Code for handling ajax requests will be the same for all controlles, is there a way to define this behaviour rule globally for whole application?

Best Answer

public function initialize()
{
    if (!$this->request->isAjax()) 
    {
        // disable layout here... how?
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
    }
}

Also you could disable the auto rendering by calling

$this->view->disable();
Related Topic