Magento 2 Registry object

Registry object in Magento 2 is one of the most useful objects.

In Magento 1, we can simply use register and registry using static method of Mage class:

In Magento 2, it supports this method also. However, we need to use class  \Magento\Framework\Registry. You can init an instance of this class in class constructor.

 

To save a variable, we use this code:

To retrieve this variable:

Registry object in Magento 2 need more steps to be usable but it’s still very helpful. So please note this, you will need it in your Magento 2 module.

 

Leave a Reply

Your email address will not be published.