What does this function do in magento 2?

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


First of all, this is Magento1 code.


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:

  • Thanks @dhiren , It's works for me :) Aug 2, 2021 at 6:10

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.