每个人!
我是zend框架的新手,我正在研究zend框架中基于ajax的选项卡。在单击我想要调用操作的选项卡时,我希望获得呈现的内容(在相应视图中呈现的内容)以将其作为响应发送。
谢谢!
答案 0 :(得分:3)
不确定您想要什么,但您可以禁用动作中的布局渲染,并仅渲染动作视图脚本,例如
public function exampleAction() {
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->layout->disableLayout();
$this->view->var = 'some var';
} else {
throw new Exception('Not an ajax requrests');
}
}
答案 1 :(得分:1)
查看:
<a href="#" class="tab">Click</a>
<div id="content"></div>
JS:
$('.tab').click(function() {
$.get('/controller/ajax', function(data) {
$('#content').html(data);
});
});
控制器:
public function ajaxAction()
{
echo 'string';
exit;
}
你只需要添加退出;在你的行动中,所以它不会再尝试渲染布局。
答案 2 :(得分:0)
public function yourAction() {
// get response and layout
$response = $this->getResponse();
$layout = $this->_helper->layout();
// rendering action's template
$this->render( 'template' );
// setting content, don't remember to echo $this->Layout()->content in the layout script
$layout->content = $response->getBody();
// here you can get your rendered content, and do something with it
$renderedContent = $layout->render( 'layout' );
// you have to clean response otherwise will be automaticaly sent
$response->clearBody();
}
答案 3 :(得分:0)
试试这个,同时确保在最后添加一个退出
$this->view->assign(array('name' => 'my name', 'msg' => 'my message'));
echo $this->view->render('message/display.phtml');
exit;
然后在.phtml文件中调用
<?php echo $this->msg; ?>