gpt4 book ai didi

magento - 在magento中调用我的模块中另一个模块的助手

转载 作者:行者123 更新时间:2023-12-02 13:38:14 25 4
gpt4 key购买 nike

如何在我的模块中调用另一个模块的助手?

当我尝试

Mage::helper('helperclass')->getValueClass('',$id)

它给了我错误:

fatal error :在第 516 行的 C:\wamp\www\example\app\Mage.php 中找不到类“Mage_Helperclass_Helper_Data”

帮助程序类名称为 Test_Helperclass_Helper_Data。

最佳答案

这是调用助手的正确方法,但您的错误表明您没有正确设置模块。我假设您的模块存在于 app/code/local/Test/Helperclass 中,并且您已使用 app/etc/modules/Test_Helperclass.xml 文件启用了您的模块。

当您调用 Magento 的工厂时,例如 Mage::getModel()Mage::getSingleton()Mage::helper(),您不需要提供完整的类名,而是提供对您要实例化的类的引用。

其格式为模块名/类名

在我们的例子中,模块名称是helperclass(不必与模块的实际名称有任何关系,它也可以是foobar),我们的类名称是data。因此,我们本质上是在调用 Mage::helper('helperclass/data'),但 Magento 让我们将其缩短为 Mage::helper('helperclass')

我们需要告诉Magento扩展helperclass/data -> Test_Helperclass_Helper_Data背后的规则。我们在 app/code/local/Test/Helperclass/etc/config.xml 的模块配置文件中执行此操作:

<?xml version="1.0"?>
<config>
...
<global>
<helpers>
<!-- Here is where we define the mapping rule -->
<helperclass>
<class>Test_Helperclass_Helper</class>
</helperclass>
</helpers>
</global>
...
</config>

关于magento - 在magento中调用我的模块中另一个模块的助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8727810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com