Zend Framework 2: Establecer diseño usando MvcEvent

I want to change the layout using an mvc event. I've tried the following:

// $event instanceof \Zend\Mvc\MvcEvent
$serviceManager = $event->getApplication()->getServiceManager();
$controllerLoader = $serviceManager->get('ControllerLoader');
$controllerLoader->addInitializer(function ($controller) {

    // OR THIS

My aproaches don't produce any errors notices or something. Not even if layout/example doesn't exist. Why is it possible to change the layout from inside a controller with $this->layout() but not from outside with $controller->layout()?

También lo probé de esta manera:

// $event instanceof \Zend\Mvc\MvcEvent
$serviceManager = $event->getApplication()->getServiceManager();
$renderingStrategy = $serviceManager->get('DefaultRenderingStrategy');

This also does not throw out any errors but does not change anything.

How can I switch the layout from outside of the controller during runtime?

preguntado el 28 de agosto de 12 a las 13:08

2 Respuestas

aww, it was so easy: simply call it directly on the event..

// $event instanceof \Zend\Mvc\MvcEvent

Respondido 28 ago 12, 13:08

//$this instanceof Zend\Mvc\Controller\AbstractActionController

respondido 05 nov., 12:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.