CListView without model

Hi,

I use CListView to render content from an database by using models and CActiveDataprovider, which works well.

Now, there is some data which doesn’t exist in the database, but is available as an associative PHP array.

The Question now is: howto bring that data into the clistview?

I thought about different ways, but did not find a solution.

Is there a way to smuggle to data from the array to the CListView, like mapping to an “fake model” or creating an pseudo object - an object which looks like an CActiveDataprovider (but I don’t know, how to do)?

Or maybe I didn’t understood the documentation and there is something like an backdoor to bring the array data to the model/CListView?

Thank you, rall0r.

Have a look at this thread.

/Tommy

Thank you!

I’m not sure, if I understand the post completely.

I have an data-source array $source like:


[0]

--->Obj

-------->Attr1

-------->Attr2

[1]

--->Obj

-------->Attr1

-------->Attr2

It’s possible to add the values like: $source[0]->Attr1

And i can use this array as dataprovider and the "columns"-option to "map"?

like:


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

    'dataProvider'=>$source,

        'columns'=>array(

                array(

                        'name'=>'field1',

                        'value'=>'$data->Attr1',

                ),

                array(

                        'name'=>'field2',

                        'value'=>'$data->Attr2',

                ),

        ),

));

Is this correct?

…in this case the CListView will iterate trough the array?

Almost. You’ll need to use a CArrayDataProvider.

CArrayDataProvider - that looks very interesting (I never heard about that)

Thank you so much! :slight_smile:

I should have written "have a look at this post" (not thread).

Now take into account this post :D

/Tommy