2012-02-29 27 views
0

我使用get ajax调用来获取页面。通过javascript调用禁用zend布局

$.get('/notification/viewmessage',{user:username},function(data){ 
       //my code here 
      }); 

我wan't来禁用只有一些$.get调用页面的布局。 zend中的默认布局禁用功能是$this->_helper->layout->disableLayout(); 但我不想在所有页面请求中这样做。 我可以通过在js请求本身中添加一些代码来做到这一点吗? 在此先感谢。

+1

你可以添加一个变量到URL然后检查页面中。 – 2012-02-29 05:13:47

回答

1

你可能想要一个标志添加到您的viewmessage脚本。

$.get('/notification/viewmessage?layout=false',{user:username},function(data){ 
    //my code here 
}); 

然后在viewmessage脚本你有这样的事情在脚本的顶部。

if($this->getRequest()->getParam('layout') == 'false') 
{ 
    $this->_helper->layout->disableLayout(); 
} 
1

这就是AjaxContext action helper开箱即用。

只需将配置调用添加到您的控制器的init()方法中,创建.ajax.phtml视图并将其呈现在普通视图脚本中。例如

public function init() 
{ 
    $this->_helper->ajaxContext->addActionContext('viewmessage', 'html') 
           ->initContext('html'); 
           // this avoids having to pass a format param 
} 

notification/viewmessage.phtml

<?php echo $this->render('notification/viewmessage.ajax.phtml') ?> 

,并把您的正常浏览内容在notification/viewmessage.ajax.phtml