zend-framework – 如何捕获Zend视图输出而不是实际输出它

问题:有时在我们的zend控制器中,我们不希望脚本直接输出,而是想要该脚本的内容.一个例子:当我们需要结果时,视图脚本的html输出被包含在另一个结构中,如 JSON或XML,以便在客户端进行处理.

我在堆栈溢出时发现了结果,但不是那么快,因为它处于不同的上下文中.我现在已经为此困难了2天了.事实证明这很简单:

// in our controllers' action method
    $this->_helper->layout()->setLayout('empty');    // disable layout
    $this->_helper->vieWrenderer->setnorender(true); // make sure the script is not being rendered

    // any of your code here
    $html = $this->view->render('projects/climate.phtml');  // return the view script content as a string
    $json = array('html'=>$html,'initData'=>'my other needed data');
    echo json_encode($json);

我希望这很清楚,对某人有用.

尝试使用
public myAction () {
    $this->_helper->json(array(
        'html'    => $this->view->render('projects/climate.phtml'),'initData'=> 'my other needed data',));
}

Json行动助手通常会这样做

>禁用vieWrenderer>禁用布局> json_encode数组

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...