3

我想为我发送的电子邮件使用布局。我目前正在为网页使用 Zend Layout,但也想为我的电子邮件设置主题。

这是我尝试过的。

这是我发送电子邮件的功能

    $layout = Zend_Layout::getMvcInstance();
    $this->_view->render($template);
    $html = $layout->render('email');
    $this->setBodyHtml($html,$this->getCharset(), $encoding);
    $this->send();

电子邮件布局很简单

    The email content
    <?php echo $this->layout()->content; ?>

当它作为电子邮件发送时,它只是...

    The email content
4

2 回答 2

5

您的原始方法非常接近;但是,您必须执行几个额外的步骤Zend_Layout才能获得所需的内容:

$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('email')
    ->disableLayout();
$layout->content = $this->_view->render($template);
$html = $layout->render();

$this->setBodyHtml($html, $this->getCharSet(), $encoding)->send();

调用Zend_Layout::disableLayout()阻止布局渲染的直接输出,并允许您将渲染的布局存储在$html变量中。然后,您必须手动将Zend_View模板的渲染存储到Zend_Layout::content变量中。在那之后,你就设置好了。

您还可以使用在布局Zend_Layout::setView中设置实例,Zend_View以便在渲染布局时可以访问视图变量。您可能还可以编写一个视图助手来处理这个问题。

于 2012-01-05T03:17:37.987 回答
0

您是否考虑过只使用 Zend_View 来生成您的电子邮件模板?

于 2010-07-21T18:05:54.480 回答