Sha*_*ell 3 php zend-framework zend-layout
我想使用我发送的电子邮件的布局.我目前正在为网页使用Zend Layout,但我也希望对我的电子邮件进行主题化.
这是我尝试过的.
这是我发送电子邮件的功能
$layout = Zend_Layout::getMvcInstance();
$this->_view->render($template);
$html = $layout->render('email');
$this->setBodyHtml($html,$this->getCharset(), $encoding);
$this->send();
Run Code Online (Sandbox Code Playgroud)
电子邮件布局很简单
The email content
<?php echo $this->layout()->content; ?>
Run Code Online (Sandbox Code Playgroud)
当它作为电子邮件发出时,它只是......
The email content
Run Code Online (Sandbox Code Playgroud)
小智 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();
Run Code Online (Sandbox Code Playgroud)
调用以Zend_Layout::disableLayout()防止直接输出布局渲染,并允许您将渲染的布局存储在$html变量中.然后,您必须手动将Zend_View模板的呈现存储到Zend_Layout::content变量中.在那之后,你就定了.
您还可以使用在布局中Zend_Layout::setView设置实例,Zend_View以便在呈现布局时可以访问视图变量.你也可以编写一个视图助手来处理这个问题.