更新时间:2023-11-30 10:09:46
您的模块需要帮助程序类的原因是 system.xml 文件中的module
自变量:
The reason your module needs a helper class is the module
argument in the system.xml file:
<cashondelivery translate="label" module="cashondelivery">
Magento将module
参数传递给Mage::helper()
工厂方法.依次将类ID补全为cashondelivery/data
.
Magento passes the module
argument to the Mage::helper()
factory method. This in turn completes the class id to cashondelivery/data
.
Mage::helper('cashondelivery');
// identical to Mage::helper('cashondelivery/data');
现在,Magento通过查找缺少的节点global/helpers/cashondelivery/class
来检查要使用的类前缀.
Now Magento checks for the class prefix to use by looking for the node global/helpers/cashondelivery/class
which is missing.
到目前为止,它还很简单,但是在这里可能有些让人困惑.
如果Magento找不到助手类的前缀,它会尝试通过在类ID的前面加上mage_
并附加_helper
来弥补.
因此,这将为您提供mage_cashondelivery_helper
作为类前缀,并为mage_cashondelivery_helper_data
作为完整的类名.
Rather straightforward so far, but here is where it might be a little confusing for some.
If Magento doesn't find a helper class prefix, it tries to makes one up by prefixing the class id with mage_
and appending _helper
.
So this gives you mage_cashondelivery_helper
as the class prefix, and mage_cashondelivery_helper_data
as the full class name.
自动加载器将其转换为 Mage/Cashondelivery/Helper/Data.php ,找不到该文件,因此您遇到的异常.
The autoloader turns this into Mage/Cashondelivery/Helper/Data.php, which can't be found, and hence the exception you are experiencing.
除了创建Companyname_Cashondelivery_Helper_Data
类外,还需要将类组映射添加到config.xml文件中,如下所示:
Besides creating the Companyname_Cashondelivery_Helper_Data
class, you need to add the class group mapping to your config.xml file as follows:
<global>
<helpers>
<cashondelivery>
<class>Companyname_Cashondelivery_Helper</class>
</cashondelivery>
</helpers>
</global>
您所缺少的只是该类组到类前缀的映射.
This class group to class prefix mapping is all you are missing.