目前我正在尝试使用Zend Framework 2构建一个应用程序,该应用程序通过ajax请求合并模态屏幕。我的计划是在将modal指定为URL参数时禁用布局。但是,如果我尝试下面的代码,我会收到以下错误:
Zend\View\Exception\DomainException:
Inconsistent state; child view model is marked as terminal
使用此代码:
$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);
有人可以告诉我怎么做,或告诉我这段代码有什么问题吗?
谢谢!
答案 0 :(得分:1)
好的,答案已在另一个论坛中找到:
$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);
}
});
来自此论坛主题:Zend Framework Contributor