簡體   English   中英

Magento致命錯誤:在非對象上調用成員函數addFieldToFilter()

[英]Magento Fatal error: Call to a member function addFieldToFilter() on a non-object

我試圖覆蓋第三方擴展中的模型,以便可以向它使用的數據庫表中添加更多列並進行操作。 我在config.xml添加了以下內容:

<marketplace>
     <rewrite>
         <userprofile>ZeroBars_Marketplacepayment_Model_Userprofile</userprofile>
     </rewrite>
</marketplace>

並將Userprofile.php文件復制到我模塊的Model文件夾中。 Userprofile中的代碼調用了我要覆蓋的先前模型的集合:

public function getPartnerProfileById($partnerId) {
        $data = array();
        if ($partnerId != '') {
            $collection = Mage::getModel('marketplace/userprofile')->getCollection();
            $collection->addFieldToFilter('mageuserid',array('eq'=>$partnerId));

...

現在我因調用addFieldToFilter Fatal Error 我也嘗試過復制Mysql4中的文件,但是我不確定如何在配置中為其添加替代。 我如何找出出了什么問題?

KRay,要獲取表集合,則需要為該模型定義Define Collection

我您需要對該模塊的類收集文件進行分類,以獲取表的所有數據

集合文件路徑為Collection.php app / code / yourcodePOol /您的文件名/模塊名稱/模型/資源/用戶配置文件/

<?php
class YourPackagename_Modulename_Model_Resource_Userprofile_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    protected function _constuct(){
        $this->_init('marketplace/userprofile');    
    }
}

如果您使用mysql4作為資源模型,請嘗試

   <?php
    class YourPackagename_Modulename_Model_Mysql4_Userprofile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
    {
        public function _construct()
        {
            $this->_init('marketplace/userprofile');
        }
    } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM