How to Set Global Variable in Magento?

Managing global variable in Magento with help of registry pattern.Registry means registering or creating a new variable which is to be used later on in the project/code. These global variables can use in many application.

Magento registry has two basic functions which are used to register or un-register your variables for later use.

register() – this registers your variables which can be the integer, string or an array.

unregister() – unregisters/destroys your registered variable.

registry() – used to call the registered variable

//this part creates global variable
 
 Mage::register('variable_name', $news);
 
 //this part calls the variable
 
 Mage::registry('variable_name');        
 
 //this part unsets the variable
 
 Mage::unregister('variable_name');  

That’s it, it is as simple as that.I think this is enough for you to understand Magento Registry. I would love to hear your experiences of working with Magento registry.If you face any problems or need our professional services, please email us at [email protected]

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.