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:
- I experimented with changing the config.xml
<rms>
tag to something arbitrary that I knew was wrong, and the error still remained identical. - 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.
- Compilation is disabled already, that's not the issue.
Best Answer
You configured your helper class like this.
So when you request you helper class with
Mage::helper('rms')
, Magento will trace your module, since it defines the helper alias namerms
and then pick class name associate with it. So in this case, Magento hasNewHope_Rms_Helper
. The next step magento checks, whether you requested in particular helper class name. For example, if you were requested a helper class likeMage::helper(rms/example)
, then magento will append thisexample
part to the class that already picked from your configuration and thus completes the class generation process(Here the class would beNewHope_Rms_Helper_Example
). However if we didn't specify any specific helper name, then by default, Magento assumes this class name asData
. So in your case, Magento forms final helper class asNewHope_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 inapp/code/community/NewHope/Rms/Helper/Data.php
. Then again inapp/code/core
directory and then again inlib
directory. In your case, Magento can't find the helper class. So as a result it will throw an error.(Note location generated isNewHope\Rms
and notNewHope\RmsUpdate
).So the configuration that you need here is
So this will generate a class
NewHope_RmsUpdate_Helper_Data
and thus first it will look in the locationapp/code/local/NewHope/RmsUpdate/Helper/Data.php
. The file content should look like this.Hope that will give you an idea on what is really happens in the backside