0

What does this function do in magento 2?

$this->_initLayoutMessages('checkout/session');
return $this;

I am new in Magento & I am going to migrating M1-> M2 , So can anyone please let me know how to use _initLayoutMessages('checkout/session') in Magento 2?

1 Answer 1

0

First of all, this is Magento1 code.

$this->_initLayoutMessages('checkout/session');

And you can use following code in Magento2 :

protected $messageManager;

public function __construct(\Magento\Framework\Message\ManagerInterface $messageManager)
{
     $this->messageManager = $messageManager;
}

With this, you can call one of the following messages:

$this->messageManager->addSuccess(__("Success"));
$this->messageManager->addError(__("Error"));
$this->messageManager->addWarning(__("Warning"));
$this->messageManager->addNotice(__("Notice"));
1
  • Thanks @dhiren , It's works for me :) Commented Aug 2, 2021 at 6:10

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.