0

I am wokring on coding standard and need to replace echo with $this->getResponse()->setBody($relatedBlock) But below code is not working for me. with echo it working perfectly.

public function showpopupAction(){

$this->loadLayout();

if($this->getLayout()->getBlock('minicart_head')){
    $relatedBlock = $this->getLayout()->getBlock('minicart_head')->toHtml();

    $this->getResponse()->clearHeaders()->setHeader('Content-type','text/xml',true);
    $this->getResponse()->setBody($relatedBlock);

}
6
  • Hi, what response do you receive? 200 and 0bite ? Probably script fall down some where later? If you make echo - it will show your xml immediately (with std output) , but when using response - it will be rendered when response object is rendered. Can you copy complete action code? Commented Jul 28, 2017 at 7:18
  • 1
    @AlexSilenko thanks you are right simple return do the trick for me. You can put as answer. Commented Jul 28, 2017 at 7:46
  • You can check what you have in response body in lib\Zend\Controller\Response\Abstract.php public function outputBody() { $body = implode('', $this->_body); echo $body; } Probably body is rewriten on some observer, etc.. Commented Jul 28, 2017 at 7:57
  • @AlexSilenko i got the solution. it is simple after $this->getResponse()->setBody($relatedBlock); return; the trick will stop executing the other script Commented Jul 28, 2017 at 7:59
  • Cool. That;s what I meant Commented Jul 28, 2017 at 8:21

1 Answer 1

1

You can check what you have in response body in

lib\Zend\Controller\Response\Abstract.php 

public function outputBody() { $body = implode('', $this->_body); echo $body; } 

Probably body is rewriten on some observer, etc..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.