Magento registry

Magento Registry

Magento has a way to store global data in the registry object which can be stored and accessed
using the following two functions -:

  • Mage::register($key,$value);
  • Mage::registry($key);

This can be very useful, if you want to access the data across multiple pages. Magento also stores product and category objects in the registry and can be accessed using the following snippets -:

$currentCategory = Mage::registry('current_category');
echo $currentCategory ->getName(); $currentProduct = Mage::registry('current_product');
echo $currentProduct->getName();

Let see how you can store your own data in Magento registry -:

The below line of code will store your global data in the my_key

Mage::register("my_key","my_value");

And the below line of code can be used anywhere on the page to retrieve the same data.

echo Mage::registry("my_key");

N.B. – This is available only in the current user session.

Discover more from WHO WILL CARE eCommerce

Subscribe now to keep reading and get access to the full archive.

Continue reading