disabling view with in action in ZF2

2019-01-31 12:58发布

I am struggling with disabling view in ZF2 $this->_helper->viewRenderer->setNoRender(); or (true) with no luck as it always says there

PHP Fatal error:  Call to a member function setNoRender() on a non-object in ../module/Location/src/Location/Controller/LocationController.php on line 190

9条回答
我命由我不由天
2楼-- · 2019-01-31 13:52
public function testAction()
{   
    return false;
}

simply return false.

查看更多
虎瘦雄心在
3楼-- · 2019-01-31 13:55

public function indexAction() {

    $news = $this->em->getRepository('Admin\Model\News');
    foreach ($news->findAll() as $new) {


        $res = $this->getResponse()->setContent($new->toXml());
    }





    return $res;

}
查看更多
疯言疯语
4楼-- · 2019-01-31 13:58

I found a simple solution for disable layout. In my ajaxAction

public function ajaxAction()
{   
     if ( $this->getRequest()->isXmlHttpRequest() ) {

          $this->layout( 'layout/ajax-layout' );

     }
}

And in \module\Application\view\layout\ajax-layout.phtml

<?php echo $this->content; ?>
查看更多
登录 后发表回答