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

标签 zend-framework view

我有一个带有简单示例操作的 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/

相关文章:

php - 发送 : How to add webpage title in all my views?

zend-framework - Zend View 脚本路径设置

image - 当我尝试缓存私有(private)图像(使用修改后的 header )时, header 被省略

php延迟发送数据5分钟

zend-framework - 我的 OpenID 正确吗?

Android:如果图像不存在,返回 createFromPath 方法是什么?

mysql - 这是一个错误吗?还是错误?或者查询错误?

android - 如果 maxLines = 1,为什么字符/剪切 TextView 中的文本?

javascript - 使用 Css 的导航栏样式

css - Drupal 6 - "Link this field to node"第一个列表项不是斜体