Pdf: Restore previous state after rendering content

In case an exception occurs its output was previously merged
with the rendered content or even PDF..
This commit is contained in:
Johannes Meyer 2020-01-10 14:08:21 +01:00
parent c12da7b7ac
commit 5943e6bde9
2 changed files with 12 additions and 7 deletions

View File

@ -51,14 +51,19 @@ class Pdf
Environment::raiseExecutionTime(300); Environment::raiseExecutionTime(300);
$viewRenderer = $controller->getHelper('viewRenderer'); $viewRenderer = $controller->getHelper('viewRenderer');
$controller->render( $viewRenderer->postDispatch();
$viewRenderer->getScriptAction(),
$viewRenderer->getResponseSegment(), $layoutHelper = $controller->getHelper('layout');
$viewRenderer->getNoController() $oldLayout = $layoutHelper->getLayout();
); $layout = $layoutHelper->setLayout('pdf');
$layout = $controller->getHelper('layout')->setLayout('pdf');
$layout->content = $controller->getResponse(); $layout->content = $controller->getResponse();
$html = $layout->render(); $html = $layout->render();
// Restore previous layout and reset content, to properly show errors
$controller->getResponse()->clearBody($viewRenderer->getResponseSegment());
$layoutHelper->setLayout($oldLayout);
$imgDir = Url::fromPath('img'); $imgDir = Url::fromPath('img');
$html = preg_replace( $html = preg_replace(
'~src="' . $imgDir . '/~', '~src="' . $imgDir . '/~',

View File

@ -484,8 +484,8 @@ class ActionController extends Zend_Controller_Action
} }
if ($req->getParam('format') === 'pdf') { if ($req->getParam('format') === 'pdf') {
$this->shutdownSession();
$this->sendAsPdf(); $this->sendAsPdf();
$this->shutdownSession();
exit; exit;
} }