So I have tried to find an answer to this but just seem to find it. I have the need to pass data to the CGridview but CActiveDataProvider is not a viable option. As such I’ve been using the CArrayDataProvider. This works just fine except that it seems to require all the data to be present in the array. While this is fine for small datasets this particular dataset can have as much as 30k records in it and storing that much data is expensive when all I want to do is show the user 10 items at time.
Here is a simplified example of how I usually build the data (in case I’ve been doing it wrong):
$query = 'SELECT pid, last_name, first_name, address FROM people ORDER BY last_name, first_name;'; $cmd = Yii::app()->createCommand($query); $result = $cmd->query(); $data = array(); foreach($result as $row) $data = array('pid'=>$row['pid'], 'last_name'=>$row['last_name'], 'first_name'=>$row['first_name'], 'address'=>$row['address']); $dp = return new CArrayDataProvider($data, 'id'=>'pid',- array( 'pagination'=>array('pageSize'=>10), ));
Outside the world of Yii I would generally just use limits + offsets but I don’t see how I can do that with CArrayDataProvider. Is there a way to do this? If not is there another dataprovider class that I could use? I’m willing to extend my own dataprovider if need be but I obviously if there is a standard way of doing this that would be ideal.