Stijn Koopal
Stijn Koopal

Reputation: 143

Zf2 Disable layout application wide

Currently I am trying to build an application with Zend Framework 2 that incorporates modal screens through an ajax request. My plan was to disable the layout when modal is specified as a URL parameter. However if I try the code below, I get the following error:

Zend\View\Exception\DomainException:
Inconsistent state; child view model is marked as terminal

With this code:

$events->attach ( MvcEvent::EVENT_DISPATCH, function ( MvcEvent $e ) use ($sm) {
    if ($e->getRequest()->getQuery('modal') !== null) {
        $result = $e->getResult();
        if ($result instanceof ViewModel) {
            $result->setTerminal(true);
        }
    }
}, -100);

Can somebody tell me how to do this, or tell me what is wrong with this code?

Thank you!

Upvotes: 1

Views: 937

Answers (1)

Stijn Koopal
Stijn Koopal

Reputation: 143

Ok the answer has been found in another forum:

$sharedEvents = $app->getEventManager()->getSharedManager();
$sharedEvents->attach('Zend\Mvc\Controller\AbstractController','dispatch', function($e) {
    $result = $e->getResult();
    $request = $e->getApplication()->getRequest();
    if ($result instanceof ViewModel && $request->getQuery('modal') !== null) {
       $result->setTerminal(true);
    }
}); 

From this forum topic: Zend Framework Contributor

Upvotes: 1

Related Questions