Call to a member function setPageSize() on a non-object
-
09-12-2020 - |
题
How to use query to get result in Magento admin grid & set into collection?
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query="MY_SQL_QUERY";
$result = $readConnection->fetchAll($query);
$this->setCollection($result);
This is showing error as Call to a member function setPageSize() on a non-object
解决方案
$result
is not an object of magento library class Varien_Data_Collection
.
SetPageSize()
works whenever a collection is instance of Varien_Data_Collection
class.
If you want to use this function then you need convert you that collection ($result )
to Varien_Data_Collection
.Then setPageSize() will work.
$collection = new Varien_Db_Collection(); foreach($result as $row){ $rowObj = new Varien_Object(); $rowObj->setData($row); $collection->addItem($rowObj); } $collection->setPageSize($size)
See more detail Check out Alan Storm blog