更新时间:2023-11-30 10:18:58
你的模块需要辅助类的原因是 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.