1

I realize there are questions just like this one, but none of the answers apply to me so far.

I am building a custom module that works, except the helper class won't load. I'm calling it with Mage::helper('rms') and I get

Fatal error: Class 'NewHope_Rms_Helper_Data' not found in C:\wamp\www\app\Mage.php on line 546

Here's my module config. The observer correctly get triggered after a user successfully registers:

app/code/local/NewHope/RmsUpdate/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <NewHope_RmsUpdate>
            <version>0.0.1</version>
        </NewHope_RmsUpdate>
    </modules>
    <global>
        <events>
            <customer_register_success>
                <observers>
                    <newhope_rmsupdate>
                        <class>newhope_rmsupdate/observer</class>
                        <method>import_new_customer_to_rms</method>
                        <type>singleton</type>
                    </newhope_rmsupdate>
                </observers>
            </customer_register_success>
        </events>
        <models>
            <newhope_rmsupdate>
                <class>NewHope_RmsUpdate_Model</class>
            </newhope_rmsupdate>
        </models>
        <helpers>
            <rms>
                <class>NewHope_Rms_Helper</class>
            </rms>
        </helpers>
    </global>
</config>

app/code/local/NewHope/RmsUpdate/Helper/Data.php

<?php

class NewHope_Rms_Helper_Data extends Mage_Core_Helper_Abstract
{
    ...
}

app/code/local/NewHope/RmsUpdate/Model/Observer.php

<?php

class NewHope_RmsUpdate_Model_Observer
{
    public function import_new_customer_to_rms(Varien_Event_Observer $observer)
    {
        $customer = $observer->getCustomer();

        //Fatal Error shows up here, when I try to load the rms helper!
        $rms_updated = !!Mage::helper('rms')->CreateRmsUser($customer);

        Mage::log(
            sprintf('%s (%s) registered. RMS Update: %s',
                $customer->getEmail(),
                $customer->getId(),
                $rms_updated ? 'Successful' : 'Failed'),
            null,
            'user-registration.log');
    }
}

I have these clues:

  1. I experimented with changing the config.xml <rms> tag to something arbitrary that I knew was wrong, and the error still remained identical.
  2. In between every attempt I manually deleted the var/cache folder, so even though the above points seem like a caching issue, I think they are not.
  3. Compilation is disabled already, that's not the issue.
3

You configured your helper class like this.

<helpers>
    <rms>
        <class>NewHope_Rms_Helper</class>
    </rms>
</helpers>

So when you request you helper class with Mage::helper('rms'), Magento will trace your module, since it defines the helper alias name rms and then pick class name associate with it. So in this case, Magento has NewHope_Rms_Helper. The next step magento checks, whether you requested in particular helper class name. For example, if you were requested a helper class like Mage::helper(rms/example), then magento will append this example part to the class that already picked from your configuration and thus completes the class generation process(Here the class would be NewHope_Rms_Helper_Example). However if we didn't specify any specific helper name, then by default, Magento assumes this class name as Data. So in your case, Magento forms final helper class as NewHope_Rms_Helper_Data.

The name of the class is an indication to the location where that class should be defined. That means Magento will now look for your helper in app/code/local/NewHope/Rms/Helper/Data.php. If it is not present there, it will look in app/code/community/NewHope/Rms/Helper/Data.php. Then again in app/code/core directory and then again in lib directory. In your case, Magento can't find the helper class. So as a result it will throw an error.(Note location generated is NewHope\Rms and not NewHope\RmsUpdate).

So the configuration that you need here is

<helpers>
    <rms>
        <class>NewHope_RmsUpdate_Helper</class>
    </rms>
</helpers>

So this will generate a class NewHope_RmsUpdate_Helper_Data and thus first it will look in the location app/code/local/NewHope/RmsUpdate/Helper/Data.php. The file content should look like this.

<?php
class NewHope_RmsUpdate_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Hope that will give you an idea on what is really happens in the backside

2

your module helper class name should be in

app/code/local/NewHope/RmsUpdate/Helper/Data.php

class NewHope_RmsUpdate_Helper_Data extends Mage_Core_Helper_Abstract
{
    ...
}

and your xml file should be

<helpers>
            <rms>
                <class>NewHope_RmsUpdate_Helper</class>
            </rms>
        </helpers>

and call Mage::helper('rmsupdate');

  • You are right except to the point Mage::helper('rmsupdate'). It is wrong. It will generate an error. Take a look on my answer. – Rajeev K Tomy Sep 2 '14 at 1:24
1

There are only one issue on helper class declaration in config.xml.

as your helper class path is local/NewHope/RmsUpdate/Helper/Data.php that means that your helper base class is NewHope_RmsUpdate_Helper.

and that why config.xml helper class code look like

<class>NewHope_RmsUpdate_Helper</class>

and as you call helper at observer file using Mage::helper('rms') that means helper type defined you as rms and <rms></rms> defined as helper type

that helper configuration is

        <helpers>
            <rms>
                <class>NewHope_RmsUpdate_Helper</class>
            </rms>
        </helpers>
0

I faced the same issue, the mistake i did compilation mode was enabled when i install extension from magento connect manager.

i reinstall the extension after disabled compilation mode System->Tools->Compilation and it worked for me without any error. Hope this help other peoples.

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.