Magento : Registry Pattern

Magento Registry Pattern is used globally to store different types of memory values for different purposes.

Magento Registry Patterns create new global variables which get registered in Magento environment.

There are three registry methods which are defined as static methods and can be accessed anywhere in Magento store to share information anywhere within your Magento store.

1) Mage::register(‘key’,’value’)
2) Mage::unregister(‘key’)
3) Mage::registry(‘key’)

1) The register method is a static method defined in app/Mage.php and is like to set a global variable.

Syntax: Mage::register(‘key_name’, $valueToRegister);

2) To fetch registry or globally registered variable, we use another static method defined in app/Mage.php.

Syntax: $variableToStore = Mage::registry(‘key_name’);

3) If you want to unregister the registered variable, use the unregister method to remove it from the registry.

Syntax: Mage::unregister(‘key_name’);

Leave a Reply