I dont know if this is a bug of ZF2 or I just dont understand it well, but Im very excited why is this happening.
I'm using a solution to change layout of each module globaly by attaching a Dispatch event. (for example from http://framework.zend.com/manual/2.1/en/modules/zend.view.quick-start.html#dealing-with-layouts, last example)
It's working well, but problem is, when in some action I want to setTerminate(true); (for Ajax call) it will not display only content of controller/action template, but only layout template without content! And that is what I'm not expecting.
This is how to simulate this, set layout in dispatch function (instead of attaching event, to make it cleaner) and then setTerminate in controller's action.
public function dispatch(Request $request, Response $response = null)
{
parent::dispatch($request, $response);
$this->layout('layout/new');
}
public function indexAction()
{
$model = new ViewModel();
$model->setTerminal(true);
return $model;
}
Again, I'm expecting that this will display only content of controler/index template, but instead of that, it display only content of layout/new without content.
I tried to set layout in action, and it working how I'm expecting.
public function indexAction()
{
$this->layout('layout/new');
$model = new ViewModel();
$model->setTerminal(true);
return $model;
}
This is working, it display only content of controller/index template and not layout.
So if I'm changing layout globaly (by attaching dispatch event) for each controller it working until I want to use one of these controllers for Ajax call and use setTerminate.
Thanks for help with that.