문제

안녕하세요. 컬렉션을 필터링하는 동안 그리드 파일에 오류가 표시됩니다.

내 그리드 파일의 코드는 다음과 같습니다.

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