Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

How do you make Zend Framework NOT render a view/layout when sending an AJAX response?

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

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?

question from:https://stackoverflow.com/questions/1498692/how-do-you-make-zend-framework-not-render-a-view-layout-when-sending-an-ajax-res

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...