Frage

Hallo. In meiner Rasterdatei wird beim Filtern der Sammlung ein Fehler angezeigt.

Hier ist der Code meiner Grid-Datei

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();
}

Hier ist mein Modell

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');
  }

}
War es hilfreich?

Lösung

Nun, Sie können nur das anwenden addFieldToFilter Sobald Sie die Sammlung haben, gehen Sie stattdessen wie folgt vor:

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

Du solltest tun:

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

Eine einfachere Syntax könnte auch sein:

$collection = Mage::getResourceModel('custom_abc/custom_collection')
            ->addFieldToFilter('custom_id',1);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top