2012-02-13 242 views
0

我正在嘗試爲自定義屬性設置自定義後端模型。問題在於Magento會將'Mage'目錄加到路徑中,所以我無法將所有文件保留在我的擴展目錄中。將自定義後端模型添加到自定義屬性

代碼:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 
$setup->addAttribute('catalog_category', $postData['attribute_code'], array(
         'label'  => $postData['frontend_label'], 
         'input'  => $postData['frontend_input'], 
         'backend' => 'my_company/myextension_model_category_attribute_backend_file', 
         'required' => $postData['is_required'], 
         'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
         'group'  => $postData['attribute_group_name'], 
         'sort_order' => $postData['sort_order'] 
)); 

相反的路徑是相對於我的延伸,「法師」被前綴並導致這個錯誤:

Warning: include(Mage/My_Company/Model/My_Extension/Model/Category/Attribute/Backend/File.php): failed to open stream 

我還沒有找到一個可行的解決方案使用addAttribute()方法。

在進行故障排除時,並未立即明確Magento在何處預先設置路徑。

一切都很好(我正在使用文件渲染器),但它沒有正確保存後端,當然。

我在Magento 1.6.1上。

回答

1

仔細檢查,如果您的應用程序/代碼/本地/ Your_Company/Your_Extension的/ etc/config.xml中註冊你的模型Magento的系統:

<global> 
    ... 
    <models> 
     <my_company> 
      <class>Company_Extension_Model_Category_Attribute_Backend_File</class> 
     </my_company> 
    </models> 
    ... 
</global> 
+0

關閉,看來我的語法是關閉的。更改我的配置,然後將我的後端更改爲'company/category_attribute_backend_file',導致路徑'Company/Extension/Model/Category/Attribute/Backend/File.php'的打開流警告失敗 – 2012-02-13 02:21:17

+0

好吧,將後端添加到「擴展名/文件」工作。我也必須更新我的班級名稱/路徑。謝謝先生。 – 2012-02-13 02:29:43