Helpers
There is one part of Magento functionality that gets equally used across all the individual functionality mentioned so far, and that's helpers. Magento helper is a class that usually extends the Mage_Core_Helper_Data
class directly found in the app/code/core/Mage/Core/Helper/Data.php
file or at the very least derived from the Mage_Core_Helper_Abstract
class found under the app/code/core/Mage/Core/Helper/Abstract.php
file.
The Helper
classes contain various utility methods that will allow you to perform common tasks on different objects and variables. Helpers too are defined via the config.xml
elements as follows:
<?xml version="1.0"?> <config> <!-- … other elements ... --> <global> <helpers> <foggyline_happyhour> <class>Foggyline_HappyHour_Helper</class> </foggyline_happyhour> </helpers> </global> <!-- … other elements ... --> </config>
Similar to blocks and models, helpers have a class element defined to point to their folder locations within an extension. In this example, a helper is defined with the name foggyline_happyhour
.
As you are allowed to have multiple helpers under the app/code/community/Foggyline/HappyHour/Helper/
folder, it is important to know that the default helper PHP filename is Data.php
.
What this really means is that when you execute a statement such as Mage::helper('foggyline_happyhour');
, Magento will load the Data.php
helper. If, however, you execute a statement such as Mage::helper('foggyline_happyhour/image');
, Magento will load the Image.php
helper (the app/code/community/Foggyline/HappyHour/Helper/Image.php
file).