简体   繁体   中英

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

I am attempting to override a model in a third party extension so I can add a few more columns to the database table it uses and manipulate them. I've added the following in config.xml :

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

and copied the Userprofile.php file into my module's Model folder. The code in Userprofile makes a call to the collection of the previous Model that I am overriding:

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

...

and I am now served with a Fatal Error for calling addFieldToFilter . I've tried copying over the files in Mysql4 as well but I am not sure how to go about adding an override for them in config. How can I sleuth out what is going wrong?

KRay, for get collection of table then you need Define Collection for that model

I you need to class collection file of that module which is fetch all data of the table

Collection file path is Collection.php app/code/yourcodePOol/your pakkage name/Modulename/Model/Resource/Userprofile/

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

If you using mysql4 as resource model then try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM