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’);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s