Méthode non valide Custom_Abc_Model_Custom::addFieldToFilter Panneau d'admin de Magento CE 1.9.2
-
29-09-2020 - |
Question
Bonjour Dans ma grille de fichier alors que le filtrage de la collection, mais il montre l'erreur.
Voici le code de mon fichier raster
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();
}
Voici mon modèle
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');
}
}
La solution
Eh bien, vous ne pouvez appliquer les addFieldToFilter
une fois que vous avez la collection, de sorte qu'au lieu de ceci:
$collection = Mage::getModel('custom_abc/custom')
->addFieldToFilter('custom_id',1)
->getCollection();
Vous devriez faire:
$collection = Mage::getModel('custom_abc/custom')
->getCollection()
->addFieldToFilter('custom_id',1);
Aussi un briquet à la syntaxe pourrait être:
$collection = Mage::getResourceModel('custom_abc/custom_collection')
->addFieldToFilter('custom_id',1);
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange