Zend Framework - Set No Layout for Controller

荒凉一梦 提交于 2019-12-04 18:03:13

问题


I have a Controller that I want to use for ajax scripts to call and set session variables, get information, etc. How do I set it so that that particular controller doesn't use the default layout (specifically NO layout) so that it can send XML/JSON messages back and forth?


回答1:


Like anything to do with Zend_Framework and Zend_Application, there are multiple ways to do this, but on the last few pure Zend gigs I've done, I've seen people using the following (from an action method in you controller)

$this->_helper->layout()->disableLayout();

This shuts off of the layout. If you wanted to turn off your view as well, you could use

$this->_helper->viewRenderer->setNoRender(true);

again, from an action method in the controller.




回答2:


in your controller ...

public function init() {
    if ($this->getRequest()->isXmlHttpRequest()) {
        // no Layout 
        $this->_helper->layout()->disableLayout();
        // no views
        $this->_helper->viewRenderer->setNoRender(true);
    }
}



回答3:


In your controller action, try

$this->_helper->layout->disableLayout();


来源:https://stackoverflow.com/questions/3367601/zend-framework-set-no-layout-for-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!