简体   繁体   English

通过javascript调用禁用zend布局

[英]disable zend layout by javascript call

i am fetching a page using get ajax call. 我正在使用get ajax调用获取页面。

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

i wan't to disable the layout of the page on some $.get calls only. 我不想仅在某些$.get调用上禁用页面布局。 the default layout disable function in zend is $this->_helper->layout->disableLayout(); zend中的默认布局禁用功能是$this->_helper->layout->disableLayout(); but i don't want to do this in all page requests. 但我不想在所有页面请求中执行此操作。 can i do this by adding some code in the js request itself? 我可以通过在js请求中添加一些代码来实现吗? thanks in advance. 提前致谢。

This is what the AjaxContext action helper does out of the box. 这就是AjaxContext动作助手开箱即用的功能。

Simply add the config calls to your controller's init() method, create a .ajax.phtml view and render it in your normal view script. 只需将配置调用添加到控制器的init()方法,创建.ajax.phtml视图并在普通视图脚本中呈现它。 For example 例如

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

In notification/viewmessage.phtml notification/viewmessage.phtml

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

and place your normal view contents in notification/viewmessage.ajax.phtml 并将您的普通视图内容放在notification/viewmessage.ajax.phtml

You'd probably want to add a flag to your viewmessage script. 您可能想要在viewmessage脚本中添加一个标志。

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

Then in the viewmessage script you'd have something like this at the top of the script. 然后在viewmessage脚本中,你会在脚本的顶部有这样的东西。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM