Difference Between $this->helper and Mage::helper in Magento

blockshelpertemplate

Is the following codes in the phtml $this->helper('catalog/category') and Mage::helper('catalog/category') returns the same object?

What is the meaning of using $this->helper() and Mage::helper()?

Best Answer

Basically the $this->helper is calling the function that is contained inside the current template's block class. The Mage::helper is calling the function in the "God" class.

The $this->helper normally calls a function in the class Mage_Core_Block_Abstract which checks the layout for a helper and then simply calls the normal Mage::helper if it cannot find one.

/**
 * Returns helper object
 *
 * @param string $name
 * @return Mage_Core_Block_Abstract
 */
public function helper($name)
{
    if ($this->getLayout()) {
        return $this->getLayout()->helper($name);
    }
    return Mage::helper($name);
}
Related Topic