gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:41:10 25 4
gpt4 key购买 nike

我有一个带有简单示例操作的 Controller Mycontroller:

public function exempleAction(){
// Using layout "mail"
$this->_helper->layout()->setLayout("mail");
}

我想使用以下方法获取 View 的 HTML 内容:(稍后将其用作电子邮件内容)
$view_helper  = new Zend_View_Helper_Action();
$html_content = $view_helper->action('exemple', 'Mycontroller','mymodule');

这成功地让我获得了查看内容,但 没有布局内容 . $html_content 中不包含布局“邮件”的所有 HTML 代码。

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

最佳答案

如果我没记错的话,你没有$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', '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);

关于zend-framework - Zend 捕获布局并将内容视为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23683979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com