Home » Php » php – How it's possible to disable rendering layout in case of xmlhttprequest in phalcon framework?

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

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:
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();