加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:52:35 所属栏目:PHP教程 来源:网络整理
导读:我有一个控制器Mycontroller与简单的例行动作: public function exempleAction(){ // Using layout "mail" $this-_helper-layout()-setLayout("mail");} 我希望使用以下内容获取视图的HTML内容:(稍后将其用作电子邮件内容) $view_helper = new Zend_View_He
我有一个控制器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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读