我有一个控制器 My Controller ,带有简单的示例操作:
public function exempleAction(){
// Using layout "mail"
$this->_helper->layout()->setLayout("mail");
}
我想使用以下方式获取视图的 HTML 内容:(稍后将其用作电子邮件内容)
$view_helper = new Zend_View_Helper_Action();
$html_content = $view_helper->action('exemple', 'Mycontroller','mymodule');
这成功地让我获得了视图内容,但是没有布局内容。 $html_content 中不包含布局“mail”的所有 HTML 代码。
如何捕获包括布局部分在内的整个内容?
如果我没记错的话,之后没有布局是正常的$view_helper->action('exemple', 'Mycontroller','mymodule');
事实上,布局是在 postDisatch() 中调用的Zend_Layout_Controller_Plugin_Layout
的插件。
你仍然可以尝试这个:
在您的布局“mail.phtml”中放置以下内容:
echo $this->layout()->content;
在你的方法中:
$view_helper = new Zend_View_Helper_Action();
$html_content = $view_helper->action('exemple', 'Mycontroller','mymodule');
$layout_path = $this->_helper->layout()->getLayoutPath();
$layout_mail = new Zend_Layout();
$layout_mail->setLayoutPath($layout_path) // assuming your layouts are in the same directory, otherwise change the path
->setLayout('mail');
// Filling layout
$layout_mail->content = $html_content;
// Recovery rendering your layout
$mail_content = $layout_mail->render();
var_dump($mail_content);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)