在magento中调用我的模块中另一个模块的助手
如何在我的模块中调用另一个模块的助手?
当我尝试
Mage::helper('helperclass')->getValueClass('',$id)
时,它给我错误:
致命错误:在 C:\wamp\www\example\app\Mage 中找不到类“Mage_Helperclass_Helper_Data” .php 第 516 行
帮助程序类名称为 Test_Helperclass_Helper_Data。
How can I call helper of another module in my module?
When I try
Mage::helper('helperclass')->getValueClass('',$id)
It gives me error:
Fatal error: Class 'Mage_Helperclass_Helper_Data' not found in C:\wamp\www\example\app\Mage.php on line 516
The helper class name is Test_Helperclass_Helper_Data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是调用助手的正确方法,但您的错误表明您没有正确设置模块。我假设您的模块存在于
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
的模块配置文件中执行此操作:This is the correct way to call a helper, but your error suggests that you've not set up your module properly. I presume your module exists in
app/code/local/Test/Helperclass
, and that you have enabled your module with aapp/etc/modules/Test_Helperclass.xml
file.When you call Magento's factories, such as
Mage::getModel()
,Mage::getSingleton()
, orMage::helper()
, you don't provide the full class name, but a reference to the class you'd like to instantiate.This has the format
modulename/classname
.In our case, the module name is
helperclass
(doesn't have to bare any relationship to the actual name of the module, it could just as well befoobar
), and our class name isdata
. So we're essentially callingMage::helper('helperclass/data')
, but Magento lets us shorten that down toMage::helper('helperclass')
.We need to tell Magento the rule behind expanding
helperclass/data -> Test_Helperclass_Helper_Data
. We do this in the module configuration file atapp/code/local/Test/Helperclass/etc/config.xml
: