How it's possible to disable rendering layout in case of xmlhttprequest in phalcon framework?

avasin picture avasin · Dec 18, 2012 · Viewed 8k times · Source

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?

Answer

Nikolaos Dimopoulos picture Nikolaos Dimopoulos · Dec 18, 2012
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();