7

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?

Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
avasin
  • 9,186
  • 18
  • 80
  • 127
  • What is initialize? Is this in your base controller class or something? – Big McLargeHuge Oct 09 '14 at 03:08
  • 1
    @Koveras i have extended phalcon\mvc\controller and defined this function to handle ajax requests. Please see http://docs.phalconphp.com/en/latest/reference/controllers.html#initializing-controllers – avasin Oct 09 '14 at 11:42

1 Answers1

17
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();
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
  • 2
    $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW) would be more corrert here.. but thanks a lot for idea :) – avasin Dec 18 '12 at 03:55