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.
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.
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:
Use Mage::registry() when you want to access variable in the SAME page request (e.g. passing variable from controller to template)
Use session when you want to access variables across DIFFERENT page requests (e.g. navigating from one page to another)
Mage::registry() implies creation of new global variables which can be accessed anywhere within your Magento store.
Being a static function, Magento registry can be called directly without the object being instantiated as in case of dynamic functions.
Magento registry can be called like ClassName::StaticFunctionName().
while Mage::getSingleton() is just like session in PHP.
I hope I could explain my point.