2008/9/15 Matthew Weier O'Phinney <matthew@zend.com>
Great, thanks!
I had tried this before but I must of left unwanted code somewhere from all my messing about.
Not entirely sure what the policy is on responding to mailing lists just to confirm someones answer, so heres how i've decided to handle this.
I've extended the Zend_Mail class, adding one additional method setBodyView() which accepts the name of the view script file as the first parameter, and an array of key>value pairs as the second.
class WN_Mail extends Zend_Mail {
public function __construct($charset = null){
parent::__construct($charset);
$this->setFrom('noreply@domain.com', 'Application Mailer');
}
public function setBodyView($script, $params = array()){
$layout = new Zend_Layout(Array(
'layoutPath' => APP_PATH.'layouts',
));
$layout->setLayout('email');
$view = new Zend_View;
$view->setScriptPath(APP_PATH.'email');
foreach($params as $k => $v){
$view->assign($k, $v);
}
$layout->content = $view->render($script.'.phtml');
$html = $layout->render();
$this->setBodyHtml($html);
}
};
Simple stuff, but could prove handy
Create a new instance of Zend_Layout. Zend_Layout is only a "pseudo"
singleton -- the startMvc() method registers an instance used with MVC
components, and injects it into the various helpers and plugins.
However, you can instantiate standalone versions of Zend_Layout easily:
$layout = new Zend_Layout(array('layoutPath' => ...));
$layout->setLayout('email');
$layout->content = $view->render('register.phtml');
$final = $layout->render();
Great, thanks!
I had tried this before but I must of left unwanted code somewhere from all my messing about.
Not entirely sure what the policy is on responding to mailing lists just to confirm someones answer, so heres how i've decided to handle this.
I've extended the Zend_Mail class, adding one additional method setBodyView() which accepts the name of the view script file as the first parameter, and an array of key>value pairs as the second.
class WN_Mail extends Zend_Mail {
public function __construct($charset = null){
parent::__construct($charset);
$this->setFrom('noreply@domain.com', 'Application Mailer');
}
public function setBodyView($script, $params = array()){
$layout = new Zend_Layout(Array(
'layoutPath' => APP_PATH.'layouts',
));
$layout->setLayout('email');
$view = new Zend_View;
$view->setScriptPath(APP_PATH.'email');
foreach($params as $k => $v){
$view->assign($k, $v);
}
$layout->content = $view->render($script.'.phtml');
$html = $layout->render();
$this->setBodyHtml($html);
}
};
Simple stuff, but could prove handy
没有评论:
发表评论