Difference between Mage::registry() and Session in Magento

Manoj Chaurasia picture Manoj Chaurasia · Oct 14, 2014 · Viewed 10.7k times · Source

I am really confused about when to use Mage::registry() and Mage session.

Can any one suggest what is diff between both on them and when to use.

Answer

Ryan picture Ryan · Oct 14, 2014

The Magento registry is not persisted, as in once you are on a new page you will not see those registry variables still set. I mainly use the registry to communicate between controllers and blocks.

The session will persist, but know that there are multiple namespaces for sessions in Magento, and they will be cleared at certain times, like the checkout/session being cleared after the order is placed. It's best practice to create your own namespace for your session to avoid any conflicts like duplicate variables or clearing it at the wrong time.

As always Alan Storm has some good things to read on this topic:

http://alanstorm.com/magento_registry_singleton_tutorial

How to use Session in Magento