質問

私のグリッドファイルでコレクションをフィルタリングしながら、エラーが表示されています。

これは私のグリッドファイルのコード

のコードです。
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();
}
.

これは私のモデル

です

モデル/ custom.php

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

モデル/リソース/ 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');
   }
}
.

モデル/リソース/カスタム/ 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');
  }

}
.

役に立ちましたか?

解決

addFieldToFilterのみを適用することができます。

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

あなたはするべきです:

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

も軽量な構文である可能性があります:

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

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top