Create Custom Helper Class in Magento Module – How to

helpermagento-1.7module

I've made a new module called test_helper and I want to create a helper class in this module so that I can add custom functions to be called all over my site.

I can't however seem to find any examples of just how to go about doing this. I assume I have to create some extra xml in config and ad another file somewhere that extends a base helper but I've not had any luck finding an example to build upon.

Best Answer

Your module naming convention is quite confusing - you're calling the module itself helper? For the purpose of explaining, I'm choosing to call your module myname_mymodule

In your module ./app/code/community/MyName/MyModule/etc/config.xml, within the <global> tags

<helpers>
  <mymodule>
      <class>MyName_MyModule_Helper</class>
  </mymodule>
</helpers>

Then create the file ./app/code/community/MyName/MyModule/Helper/Data.php

<?php

class MyName_MyModule_Helper_Data extends Mage_Core_Helper_Abstract{

}

Then to call that module, you would use

$helper = Mage::helper('mymodule');
Related Topic