From 60711273a004ba85789253586af4660415727773 Mon Sep 17 00:00:00 2001 From: Mat Gadd Date: Thu, 19 Sep 2013 12:37:46 +0100 Subject: [PATCH] Move the *creation* of the view back into the constructor, but keep the layout changes intact. --- Mail.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Mail.php b/Mail.php index bb839c8..5ea348e 100644 --- a/Mail.php +++ b/Mail.php @@ -82,6 +82,10 @@ protected function _calculateTemplatePath($template) public function __construct($charset = 'iso-8859-1') { parent::__construct($charset); + + // We need the view ivar immediately, since users of this class may need + // to set view variables on it before calling the setBody* methods. + $this->_createView(); } /** @@ -124,23 +128,29 @@ public function setBodyHtmlFromTemplate($template, $charset = null, } /** - * Set up the layout and view ready for rendering. + * Create the view, and store its layout state. * * @return void */ - protected function _setUpLayout() + protected function _createView() { - if (! $this->view) { - if (! \Zend_Registry::isRegistered('Ztal_View')) { - throw new \Exception('No available Ztal View'); - } + if (! \Zend_Registry::isRegistered('Ztal_View')) { + throw new \Exception('No available Ztal View'); + } - $this->view = clone \Zend_Registry::get('Ztal_View'); + $this->view = clone \Zend_Registry::get('Ztal_View'); - // Remember the state of layout so we can reinstate it after rendering. - $this->_layoutWasEnabled = $this->view->layout()->isEnabled(); - } + // Remember the state of layout so we can reinstate it after rendering. + $this->_layoutWasEnabled = $this->view->layout()->isEnabled(); + } + /** + * Set up the layout and view ready for rendering. + * + * @return void + */ + protected function _setUpLayout() + { $this->view->layout()->disableLayout(); $this->view->setCompressWhitespace(true); }