Magento Registry: Mage::register
Magento registry is a great way of sharing information anywhere in your Magento store as they are static function.In other words Magento registry implies creation of new global variables which can be accessed anywhere within your Magento store.
I have been wondering always,where is all the registry data stored in Magento ?
I know that even singleton objects are stored in the registry. And registry is just a static array variable of the Mage class.
Is registry different for different users ? I mean is it created on a per-user (per HTTP request) basis?
For example,
Mage::register('foo', 'Hello World'); //set a value for foo
Mage::registry('foo'); //will this return hello world
Is registry data stored in sessions ? If not how will Magento identify which user invoked the registry data ?
<==============================================>
Magento Registry stored in the application’s memory,when ever your script is completed running, whatever you had stored in the registry is flush(Mean load a page in Magento, one request is DONE and registry data is flushed),so there is no need to worry about clearing it out (unless the script you are running is storing large objects in the registry and is looping through a lot of data).
In such case, you have to unregister your entries when you are done with them.
Mage::unregister('name-of-registry');
Mage::unregister('foo');
The Registry is just a static property of the Mage class.The values you set with Mage::register() persist for that request only. If you want to store user specific data you should use the session, the registry is really just designed to make data portable between classes
=>>Adding To The Registry:
The method to add to the registry is as follows. It takes two parameters. The first is the unique key you would like to give your registry entry. The second is the data you are wanting to store.
Mage::register('name-of-registry-key', $your-data);
=>>Getting Data From The Registry:
When you are ready to retrieve the data you have stored, use the following method:
$var = Mage::registry('name-of-registry-key');
=>>Removing From The Registry
When and if you are ready to remove the data from the registry, there is a method to unregister it. This may be important to you, especially if you are using the registry in a loop and you are wanting to set the same registry key name more than once. The Mage::register() method will not let you set a key if it is already set.
Mage::unregister('name-of-registry-key');
Magento registry is a great way of sharing information anywhere in your Magento store as they are static function. In other words Magento registry implies creation of new global variables which can be accessed anywhere within your Magento store.
Hope this will make little clear in your mind.
Thanks
I have been wondering always,where is all the registry data stored in Magento ?
I know that even singleton objects are stored in the registry. And registry is just a static array variable of the Mage class.
Is registry different for different users ? I mean is it created on a per-user (per HTTP request) basis?
For example,
Mage::register('foo', 'Hello World'); //set a value for foo
Mage::registry('foo'); //will this return hello world
Is registry data stored in sessions ? If not how will Magento identify which user invoked the registry data ?
<==============================================>
Magento Registry stored in the application’s memory,when ever your script is completed running, whatever you had stored in the registry is flush(Mean load a page in Magento, one request is DONE and registry data is flushed),so there is no need to worry about clearing it out (unless the script you are running is storing large objects in the registry and is looping through a lot of data).
In such case, you have to unregister your entries when you are done with them.
Mage::unregister('name-of-registry');
Mage::unregister('foo');
The Registry is just a static property of the Mage class.The values you set with Mage::register() persist for that request only. If you want to store user specific data you should use the session, the registry is really just designed to make data portable between classes
=>>Adding To The Registry:
The method to add to the registry is as follows. It takes two parameters. The first is the unique key you would like to give your registry entry. The second is the data you are wanting to store.
Mage::register('name-of-registry-key', $your-data);
=>>Getting Data From The Registry:
When you are ready to retrieve the data you have stored, use the following method:
$var = Mage::registry('name-of-registry-key');
=>>Removing From The Registry
When and if you are ready to remove the data from the registry, there is a method to unregister it. This may be important to you, especially if you are using the registry in a loop and you are wanting to set the same registry key name more than once. The Mage::register() method will not let you set a key if it is already set.
Mage::unregister('name-of-registry-key');
Magento registry is a great way of sharing information anywhere in your Magento store as they are static function. In other words Magento registry implies creation of new global variables which can be accessed anywhere within your Magento store.
Hope this will make little clear in your mind.
Thanks
Comments
Post a Comment