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

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

Can anyone suggest what the difference is between them and how to use them.

+6
source share
3 answers

The Magento registry is not saved, because as soon as you are on a new page, you will not see that these registry settings are still set. I mainly use the registry for communication between controllers and blocks.

The session will persist, but be aware that there are several namespaces for sessions in Magento and they will be cleared at a specific time, for example, checkout/session will be cleared after placing the order. It’s best to create your own namespace for your session to avoid conflicts, such as duplicate variables, or to clear 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 a session in Magento

+12
source

Use Mage :: registry () when you want to access a variable in a SAME page request (for example, pass a variable from the controller to the template)

Use a session when you want to access variables through various page requests (for example, go from one page to another)

+2
source

Mage :: registry () means creating new global variables that can be accessed anywhere in your Magento store.

As a static function, the Magento registry can be called directly without an object instance, as is the case with dynamic functions.

The Magento registry can be called as ClassName :: StaticFunctionName ().

and Mage :: getSingleton () is similar to a session in PHP.

I hope I could explain my point.

-2
source

Source: https://habr.com/ru/post/976729/


All Articles