How to create new helpers in Magento custom module

1 comment
Magento's Helper classes contain utility methods that will allow you to perform common tasks on objects and variables. Sometimes you may want to add new utility methods or classes in your Magento module. Helpers are a good place to create these utility methods or classes. This tutorial will show you how you can add a new helper class to your Magento module.

1. Declare the helper

Suppose our helper name is 'Utility', in your module's config.xml, you need to declare the new helper class as follows:
<config>
 ...
 <global>
  ...
  <helpers>
   <utility> <!-- helper name -->
    <class>ModuleName_Utility_Helper</class> <!-- helper class -->
   </utility>
  </helpers>
 </global>
</config>

2. Create helper class

You need to create the helper class in 'app\code\local\\\Helper' directory. Our file name will be 'Utility.php'. The class structure will look like:
<?php
class <Namespace>_<Module>_Helper_Utility extends Mage_Core_Helper_Abstract
{
 public function myhelper() {
 
 }
}

3. Call the helper

You can call the newly created helper class as:
<?php
$utility = Mage::helper('<module>/utility');
$utility->myhelper();

1 comments:

Hi the information on this blog is just amazing it keeps us coming back time and time again ,personally i met my wife using this site so i couldnt love it any more i have done my best to promote this blog as i feel that others need to see this thang ,cheers for all your effort spent in making this fabulous site

We would love to hear from you...

back to top