What is the equivalent of Magento 1 to Magento 2?

        ->setHeader('HTTP/1.1','503 Service Unavailable')

In controller you can use following;

public function execute()
        ->setContent('503 Service Unavailable');
    return ;


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.