CActiveDataProvider for CGridView

I just wounding if I can display my owner array in CGridView.

If you have the relations setup in your model, you can set columns in the dataprovider, e.g.




<?php 

    $this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$dataProvider,

	'columns'=>array(

            'owner.username:text:Owner',

	    'owner.email:text:Email',

	    array(

	        'class'=>'CButtonColumn',

	    ),

	),

    ));

?>



Thanks Matt, but I don’t know have database table for this, I have an array= array(

‘0’=>array( ‘name’=>‘Mike’,‘age’=>23),

‘1’=>array( ‘name’=>‘Emma’,‘age’=>33)

)

How to get dataProvider?

Ahh your own array, I don’t think you’re going to be able to use Zii widgets without a dataProvider. This post talks about extending the class to use an array as one, but it seems like more trouble than it’s worth:

Zii For Non-active Records

IMHO you can. what you have to do is:

  1. create own dataProviderClass which will be implementing IDataProvider interface

  2. feed this dataProvider with this array

  3. use as with AR

Since my array is never more than 500 rows, I save it to a temp table, than use CGridView. It’s not perfect solution, but sames this is fast way to get it done.

Take a look at my CArrayDataProvider extension, this should solve your problems.

SOLVED http://www.yiiframework.com/forum/index.php?/topic/7678-zii-for-non-active-records/

Hi there.

I have a problem:

There is 2 arrays, first for the column names (example):




$names['closed'] = 'Done';

$names['active'] = 'In progress';



and array of values:




$values['Type1']['closed'] = 35;

$values['Type1']['active'] = 23;

$values['Type2']['closed'] = 55;

$values['Type2']['active'] = 575;

$values['Type3']['closed'] = 44;

$values['Type4']['active'] = 325;



I need to show it in CGridView like this:


     |In Progress|Done

Type1|    23     |  35

Type2|    575    |  55

Type3|    0      |  44

Type4|    325    |  0

Is it possible?