zend-framework – Zend捕获布局并将内容视为变量

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了zend-framework – Zend捕获布局并将内容视为变量脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个控制器Mycontroller与简单的例行动作:

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');

这成功地允许我获取视图内容但没有布局内容.布局“mail”的所有HTML代码都不包含在$html_content中.

如何捕获整个内容,包括布局部分?

解决方法

如果我没有弄错的话,在$view_helper-> action(‘exemple’,’Mycontroller’,’mymodule’)之后你没有布局是正常的.

实际上,布局是在Zend_Layout_Controller_Plugin_Layout的插件的postDisatch()中调用的.

你仍然可以试试这个:

在你的布局’mail.phtml’中把这个:

echo $this->layout()->content;

在你的方法中:

$view_helper = new Zend_View_Helper_Action();
$html_content = $view_helper->action('exemple','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);

脚本宝典总结

以上是脚本宝典为你收集整理的zend-framework – Zend捕获布局并将内容视为变量全部内容,希望文章能够帮你解决zend-framework – Zend捕获布局并将内容视为变量所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。