Magento - 如何在同一个配置中声明多个辅助类

时间:2011-09-22 20:11:29

标签: magento

有人可以告诉我如何在同一个配置文件中为同一个模块声明多个帮助器吗?

我一直在使用辅助实用程序文件已有一段时间了,但随着我的实用程序方法变得越来越长,有许多函数,我想根据功能将其拆分为单独的辅助实用程序类。所以我有一个名为Categoryhelper的类和一个名为Attributehelper的类。显然我可以这样做,但我不知道如何在config.xml中声明这些。

我已经尝试搞乱配置,进行试验和错误,但似乎无法正常工作。

以下是我最初的使用默认帮助器:

(注意 - 我的自定义模块名称称为'Helper'

<global>
...
<helpers>
    <helper>
        <class>GPMClient_Helper_Helper</class>
        </helper>
</helpers>
...

这是我尝试过的:

<helpers>
<helper>
            <class>GPMClient_Helper_Helper/Categoryhelper</class>
    </helper>
    <helper>
            <class>GPMClient_Helper_Helper/Attributehelper</class>
    </helper>

<helpers>
<helper>
            <class>GPMClient_Helper_Helper/Categoryhelper</class>
        <class>GPMClient_Helper_Helper/Attributehelper</class>
    </helper>

辅助类是应该进入自己的xml片段还是应该组合在一起?

如果有人可以发布一个声明了多个助手类的示例配置,我将非常感激。

谢谢, 伊恩

1 个答案:

答案 0 :(得分:6)

好像你错了它是如何运作的。将下一行添加到GPMClient_Helper模块config.xml

<helpers>
    <helper>
        <class>GPMClient_Helper_Helper</class>
    </helper>
</helpers>

为所有助手定义类前缀。因此,现在在GPMClient/Helper/Helper目录中,您应该创建文件Data.php,其中包含GPMClient_Helper_Helper_Data代码和任意数量的名为GPMClient_Helper_Helper_*的类。