在Zend Framework中将操作呈现给HTML电子邮件

asg*_*eo1 5 zend-framework html-email

我有一个动作,通过布局呈现一些内容.

我实际上想在电子邮件中发送此输出.在Zend Framework中实现这一目标的最佳方法是什么?

我知道我需要使用该Zend_Mail组件发送电子邮件,但我不清楚如何将我的操作的输出附加到Zend_Mail.

我已经对ContextSwitch动作助手做了一些阅读,我认为这可能是合适的,但我仍然不相信.

我还是Zend Framework的新手.我习惯使用输出缓冲等技术来捕获输出,我认为这不是在Zend中执行此操作的正确方法.

Mar*_*yor 8

从您的控制器:

// do this if you're not using the default layout
$this->_helper->layout()->disableLayout();

$this->view->data = $items;

$htmlString = $this->view->render('foo/bar.phtml');
Run Code Online (Sandbox Code Playgroud)

如果你是从一个不是Zend_Controller_Action实例的类中执行此操作,则可能必须首先创建Zend_view的实例,以执行此操作:

$view = new Zend_view();

// you have to explicitly define the path to the template you're using
$view->setScriptPath(array($pathToTemplate)); 

$view->data = $data;

$htmlString = $view->render('foo/bar.phtml');
Run Code Online (Sandbox Code Playgroud)