2012-01-04 31 views
3

我怎樣才能調用模塊中的另一個模塊的助手?在我的模塊中的另一個模塊的助手在magento

當我嘗試

法師::助手( '助手類') - > getValueClass( '',$ id)的

它給我的錯誤:

致命錯誤:類 'Mage_Helperclass_Helper_Data'在516行中找不到C:\ wamp \ www \ example \ app \ Mage.php

助手類名稱爲Test_Helperclass_Helper_Data。

+1

和config.xml中定義你的助手,文件路徑的應用程序/代碼/本地/測試/助手類/助手/ Data.php存在? – 2012-01-04 13:53:06

回答

6

這是調用助手的正確方式,但是您的錯誤表明您沒有正確設置模塊。我推測你的模塊存在於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>