How to disable layout and view renderer in ZF2?

后端 未结 3 977
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 18:01

How can i disable layout and view renderer in Zend Framework 2.x? I read documentation and can\'t get any answers looking in google i found answer to Zend 1.x and it\'s

3条回答
  •  星月不相逢
    2020-12-15 18:17

    Slightly more info on the above answer... I use this often when outputting different types of files dynamically: json, xml, pdf, etc... This is the example of outputting an XML file.

    // In the controller
    $r = $this->getResponse();
    
    $r->setContent(file_get_contents($filePath)); //
    
    $r->getHeaders()->addHeaders(
        array('Content-Type'=>'application/xml; charset=utf-8'));
    
    return $r;
    

    The view is not rendered, and only the specified content and headers are sent.

提交回复
热议问题