잘못된 방법 Custom_Abc_Model_Custom::addFieldToFilter Magento CE 1.9.2의 관리 패널
-
29-09-2020 - |
문제
안녕하세요. 컬렉션을 필터링하는 동안 그리드 파일에 오류가 표시됩니다.
내 그리드 파일의 코드는 다음과 같습니다.
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);
제휴하지 않습니다 magento.stackexchange