Convert CActiveDataProvider to associative array

Here is an example on how to convert CActiveDataProvider to a simple associative array.

$dataProvider = new CActiveDataProvider('Users');
$data = array();

foreach($dataProvider->getData() as $r)
{
    $rowArray = array();
    
    foreach($dataProvider->model->tableSchema->columns as $c) $rowArray[$c->name] = $r[$c->name];
    
    $data[] = $rowArray;
}

Columns names are read from table schema, so you don't have to know table (model) structure to use this.

Leave a Reply