如何使Zend框架不会呈现一个视图/布局发送Ajax响应时? [英] How do you make Zend Framework NOT render a view/layout when sending an AJAX response?

查看:143
本文介绍了如何使Zend框架不会呈现一个视图/布局发送Ajax响应时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zend的文件是不是真的清楚这一点。

Zend's documentation isn't really clear on this.

现在的问题是,默认情况下,Zend的自动渲染视图在每个控制器动作结束。如果您使用的是布局 - 为什么不呢? - 它也使这一点。这是罚款正常的网页,但是当你发送一个Ajax响应你不希望这一切。你怎么prevent的Zend从自动渲染上的操作按操作依据?

The problem is that, by default, Zend automatically renders a view at the end of each controller action. If you're using a layout - and why wouldn't you? - it also renders that. This is fine for normal Web pages, but when you're sending an AJAX response you don't want all that. How do you prevent Zend from auto-rendering on an action-by-action basis?

推荐答案

称这个code无论从任何动作(S)内/将要发送Ajax响应:

Call this code from within whatever Action(s) is/are going to be sending AJAX responses:

$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(TRUE);

这将禁用布局引擎的行动,并关闭自动视图显示该操作。然后,您可以只回声不管你想你的AJAX输出为,而不用担心凑凑热闹普通视图/布局的东西得到发送。

This disables the Layout engine for that action, and it turns off automatic view rendering for that action. You can then just "echo" whatever you want your AJAX output to be, without worrying about the normal view/layout stuff getting sent along for the ride.

这篇关于如何使Zend框架不会呈现一个视图/布局发送Ajax响应时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆