7

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()?

12

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.