Question

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

Was it helpful?

Solution

$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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top