1

What is the equivalent of Magento 1 to Magento 2?

Mage::app()->getResponse()
        ->setHeader('HTTP/1.1','503 Service Unavailable')
        ->sendResponse();
Manoj Kumar
  • 1,348
  • 5
  • 32
  • 56

1 Answers1

0

In controller you can use following;

public function execute()
{      
    $this->getResponse()
        ->setStatusCode(\Magento\Framework\App\Response\Http::STATUS_CODE_503)
        ->setContent('503 Service Unavailable');
    return ;
}

EDIT:

You can try injecting \Magento\Framework\Controller\ResultFactory in your class and calling $this->response->setHeader('HTTP/1.1', '503 Service Unavailable', true); (if your object is $response) and return it at end.

Vivek Kumar
  • 5,115
  • 2
  • 24
  • 50