【问题标题】:Call helper of another module in my module in magento在我的magento模块中调用另一个模块的助手
【发布时间】:2012-01-04 13:37:49
【问题描述】:

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

当我尝试时

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

它给了我错误:

致命错误:第 516 行的 C:\wamp\www\example\app\Mage.php 中找不到类“Mage_Helperclass_Helper_Data”

帮助类名称是 Test_Helperclass_Helper_Data。

【问题讨论】:

  • 你的助手是否在config.xml中定义,文件存在路径app/code/local/Test/Helperclass/Helper/Data.php?

标签: magento helper


【解决方案1】:

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

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

格式为modulename/classname

在我们的例子中,模块名称是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>

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2017-12-25
    • 1970-01-01
    • 2016-05-31
    相关资源
    最近更新 更多