The Main
Advantage of using Magento is because of its registry methods. Registry is a
term which is the method of registering or creating a new variable which you
can use it later on the functionalities or methods you want to make use of those
variables. You can able to use that variable anywhere to get the stored values
back.
There are three
registry methods available in magento which are listed below
1. Mage::register
You can register a variable using this register method
Syntax:
Mage::register(‘keyvalue’, $variablename);
Example
For example, I am going to load the product using product id and get all the
product details and I register that product details in a variable which I can
use it later on to my code
$product_id = ‘23’;$_product = Mage::getModel(‘catalog/product’)->load($product_id);Mage::register(‘product’, $_product);
2. Mage::registry
This Registery method is used for fetching the registered variable
Syntax:
$newvariable = Mage::registry(‘keyvalue’);
Example
In previous method, we register a product details. In this method we can
fetch the registered value.
$productdetails = Mage::registry(‘product’);//This keyalue should be same as that of the variable which we used to register.
3. Mage::unregister
This Method is used to unregister the variable which is registered
Syntax:
Mage::unregister(‘keyvalue’);
Example:
After fetching all the product details, if we want to remove the values
from the stored registry we can use this method.
Mage::unregister(‘product’);
No comments:
Post a Comment
Comments