I successfully created a CArrayDataProvider with the following lines of code:
$dataProvider=new CArrayDataProvider($myArray, array(
'id'=>'ID',
'sort'=>array(
'attributes'=>array(
'ID', Type', 'Name', 'Brand','CreateDate'
),
),
'pagination'=>array(
'pageSize'=>10,
),
));
This gets passed on to the view correctly where I can see the content of the CArrayDataProvider.
In this view I call:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
And from there on I don’t know what’s going on. I simply adapted the_view.php which gets generated by gii when you use the CRUD generator. So I end up with a _view.php file like this:
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('ID')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->ID), array('view', 'id'=>$data->ID)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Type')); ?>:</b>
<?php echo CHtml::encode($data->Type); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Name')); ?>:</b>
<?php echo CHtml::encode($data->Name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Brand')); ?>:</b>
<?php echo CHtml::encode($data->Brand); ?>
<br />
<br class="Apple-interchange-newline"> <b><?php echo CHtml::encode($data->getAttributeLabel('CreateDate')); ?>:</b>
<?php echo CHtml::encode($data->CreateDate); ?>
<br />
</div>
If I open the website I get the following error:
However I can see attributes in the CArrayDataProvider:
...
[_sort:private] => CSort Object
(
[multiSort] =>
[modelClass] =>
[attributes] => Array
(
[0] => ID
[1] => Type
[2] => Name
[3] => Brand
[4] => CreateDate
)
...
Can you please help me understand where my mistakes are?