Magento: How to set and get registry?

Registry means registering or creating a new variable which is to be used later on in the project/code. The registry variable acts as a global variable which can be used anywhere.

Here are the functions to register, unregister and fetch a registry variable.

register(): register a variable
unregister(): unregister a variable
registry(‘VARIABLE_NAME’): fetch registry variable value

We can store anything in the registry variable. It can be integer, string, array, etc.

The below example shows how to create, fetch and destroy registry variable.

The Store ID of the shop is stored in registry with variable name store_id. Mage::app()->getStore()->getId() gives the current store id.

Register variable


Mage::register('store_id', Mage::app()->getStore()->getId());

Fetch registry variable value


Mage::registry('store_id');

Destroy / Unregister the variable


Mage::unregister('store_id');

Hope this helps. Thanks.