2

Hello In my grid file while filtering collection but it is showing error.

Here is the code of my grid file

protected function _prepareCollection() {

    $custom_id = Mage::getSingleton('adminhtml/session')->getCustom()->getId();

    $collection = Mage::getModel('custom_abc/custom')
            ->addFieldToFilter('custom_id',1)
            ->getCollection();

    $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
    $store = $this->_getStore();

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Here is my model

Model/Custom.php

class Custom_ABC_Model_Custom extends Mage_Core_Model_Abstract
{
  public function _construct()
  {
    parent::_construct();
    $this->_init('custom_abc/custom');
  }
}

Model/Resource/Custom.php

class Custom_ABC_Model_Resource_Custom extends Mage_Core_Model_Resource_Db_Abstract 
{
  public function _construct()
   {
       $this->_init('custom_abc/custom', 'custom_id');
   }
}

Model/Resource/Custom/Collection.php

class Custom_ABC_Model_Resource_Custom_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{

  protected function _construct()
  {
      parent::_construct();
      $this->_init('custom_abc/custom');
  }

}
  • where is the class Invalid Custom_Abc_Model_Customize – Asish Hira May 11 '16 at 13:34
4

Well you can only apply the addFieldToFilter once you've got the collection, so instead of this:

$collection = Mage::getModel('custom_abc/custom')
            ->addFieldToFilter('custom_id',1)
            ->getCollection();

You should do:

$collection = Mage::getModel('custom_abc/custom')
            ->getCollection()
            ->addFieldToFilter('custom_id',1);

Also a lighter syntax could be:

$collection = Mage::getResourceModel('custom_abc/custom_collection')
            ->addFieldToFilter('custom_id',1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.