In the below code what does the ::
operator mean or do?
<?php $_helper = Mage::helper('catalog/category') ?>
Also what does the helper
do exactly?
In terms of PHP ::
is a Scope Resolution Operator. Used to access static elements of a Class.
In Magento, Mage::helper()
, here helper()
is a STATIC function listed in Mage.php
file, like public static function helper($name)
.
From your exampe, Mage::helper('catalog/category')
, this will return an Object of Mage_Catalog_Helper_Category
helper. Check this line in helper
function definition, $helperClass = self::getConfig()->getHelperClassName($name);
in PHP, :: specify scope resolution operator,
Its native php functionality for getting static function,variable
from php file.
Mage::helper() means static helper function is defined inside `app/Mage.php file`.
first get helper function from Mage.php
file,
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
Helper function is called first from mage.php
file when you can use any helper in module. They define module full path to access it.
You can get more info about this using link, Scope resolution operator
$_helper = Mage::helper('catalog/category')
Now $_helper variable get access to all function of Mage_Catalog_Helper_Category.php
file
If you want to fetch getStoreCategories()
functions from above file,
you can simple call $_helper->getStoreCategories(false,false,true)
and return store category object.