1

What is the equivalent of Magento 1 to Magento 2?

Mage::app()->getResponse()
        ->setHeader('HTTP/1.1','503 Service Unavailable')
        ->sendResponse();
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.

  • Yup.. Okay. I want to write this code inside Model file. How can I do that? – Manoj Kumar Feb 28 '18 at 6:13
  • 1
    I think models are just for accessing db, but stll I am updating my answer check if it is working – Vivek Kumar Feb 28 '18 at 6:18
  • Thanks for reply. it's asking $type is missing. from $this->resultF->create()->setHeader('HTTP/1.1', '503 Service Unavailable', true); code – Manoj Kumar Feb 28 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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