通过javascript调用禁用zend布局



我正在使用get-ajax调用获取页面。

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

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

您可能需要在viewmessage脚本中添加一个标志。

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

然后在viewmessage脚本中,您会在脚本顶部看到这样的内容。

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

这就是AjaxContext操作助手开箱即用的功能。

只需将config调用添加到控制器的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

最新更新