4

Why its mandatory to define a helper class for adding configuration to the admin panel ?

i.e: I want to add some admin panel configuration to my module, So that when a user installed my module he/she can change some parameters via System >> Configuration >> MyTestModule.

So I need to create a system.xml and add my settings there, which is ok.

But why I need to create an empty helper class to make it work ?

<global>
        <helpers>
            <test>
                <class>Namespace_Test_Helper</class>
            </test>
        </helpers>
</global>

If I don't define the helper class it'll throw an error:

failed to open stream: No such file or directory  in /Applications/MAMP/htdocs/test/lib/Varien/Autoload.php on line 93

The useless class I'm talking about is in Data.php and is something like this:

class Namespace_Test_Helper_Data extends Mage_Core_Helper_Abstract
{

}

Isn't it some kind of stupid to create an empty class if I never using it ? What's the point ? Its completely useless to create an empty Helper class in my opinion. What I missed here ? Why its mandatory? Why it throws error when we don't create it. What's the use of helper class in here ?

Any help ?

2

I do not have (a fragment) of your system.xml, but probably you have something like translate="label" somewhere and module="your_module".

Magento will load the your_module Data helper to translate the labels.

If you would set module="core" then your module doesn't have to have a helper to translate the labels as it will use the core Data helper to translate.

2

Magento uses the helper to translate strings inside the module configuration. The file does not empty, it inherits all parent methods.

  • 1
    Of course the Helper class is empty itself, it just inherits the parent class, but its empty by itself. So why we need to create a useless class ? Magento should do it automatically if nothing defined. Is it a fundamental design issue or there is a purpose that I don't aware of ? If so, what is the purpose of creating an empty class that inherits another class? – Michel Gokan Aug 9 '14 at 19:37
  • Translations belong to a module. It is useless if you don't use your module to translate anything, but probably you are using it to translate a label in a XML file. – mbalparda Apr 29 '15 at 19:36

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.