How to disbled layout for ajax request in zend framework 2

Oct 14, 2012   //   by kdecom   //   disabled layout, ZEND FRAMEWORK, zend framework tutorial, zf2  //  No Comments
How to disabled a Layout in zf2 for ajax request

I know in most project we always have to disabled the layout and you can do that in zend framework too easily…

Just add this method into your controller…

public function nolayoutAction() {
        // Turn off the layout, i.e. only render the view script.
        $viewModel = new ViewModel();
        return $viewModel;

Now let just say we wanted to display a “Hello world” on front end side so we have to pass the title as an viewModel too.

So in your controller action looks something like this…

public function indexAction() {

        $viewModel = $this->nolayoutAction();
        $viewModel->title = ‘Hello World’;
        return $viewModel;

Leave a comment