简体   繁体   中英

disable zend layout by javascript call

i am fetching a page using get ajax call.

$.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. the default layout disable function in zend is $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? thanks in advance.

This is what the AjaxContext action helper does out of the box.

Simply add the config calls to your controller's init() method, create a .ajax.phtml view and render it in your normal view script. 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

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

and place your normal view contents in notification/viewmessage.ajax.phtml

You'd probably want to add a flag to your viewmessage script.

$.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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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