Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change layout in the controller of Zend Framework 2.0

I am learning ZF2.0 beta. In ZF1 we can change layout on the fly in controller:

Zend_Layout::getMvcInstance()->setLayout('layoutname'); 

But in ZF2.0 Zend\Layout class doesn't has method getMvcInstance(). I think that it can be made using dependency injections but not sure.

like image 567
Alex Pliutau Avatar asked Feb 02 '12 13:02

Alex Pliutau


1 Answers

The ZF2 is heavily under development and no guarantee can be made the way it works now, will be the way it works when ZF2 reaches a stable state.

However, the new view layer from Zend\Mvc is recently merged so you should be able to do this now (with current master):

public function somethingAction ()  {     // Do some intelligent work      $this->layout('layout/different'); } 
like image 129
Jurian Sluiman Avatar answered Sep 22 '22 22:09

Jurian Sluiman