I have a model that results me an array of objects and when i loop trough i want to make several instances of widget gridview and pass along an array of object that comes from a relation, however the gridview is expecting a dataprovider and i'm not sure how to convert my data.
I have searched arround and someone else had the same issue but it was not solved:
http://stackoverflow...els-association
Anyone an idea what the best approach is to solve this issue?
Page 1 of 1
Instance Gridview Widget With Model Relation Data
#2
Posted 24 January 2013 - 10:29 AM
Hi zwobbel,
Did you try CArrayDataProvider? If you did, what was wrong with it? Could you explain your data and your needs a little more, probably with a pseudo code?
Did you try CArrayDataProvider? If you did, what was wrong with it? Could you explain your data and your needs a little more, probably with a pseudo code?
#3
Posted 24 January 2013 - 10:47 AM
What i tried to do in pseudo code (this is a lite version of what i do) is for example:
However, i know that the relation 'changes' will return an array objects and so its not a dataProvider.
I also tried to use the solution of stack overflow, however it did not worked it returned a php error that told me that there was no object or value or something like that..
<?php
//Controller
$model = Tickets::model()->with('changes')->findByPk(4);
//view
foreach($model as $model) {
print $model->title;
//Show the gridview
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->changes,
'columns'=>array(
'name',
),
));
}
?>
However, i know that the relation 'changes' will return an array objects and so its not a dataProvider.
I also tried to use the solution of stack overflow, however it did not worked it returned a php error that told me that there was no object or value or something like that..
#4
Posted 24 January 2013 - 11:03 AM
Something like this won't work?
<?php
//Controller
$models = Tickets::model()->with('changes')->findAllByAttributes(...);
//view
foreach($models as $model) {
print $model->title;
//Show the gridview
$dataProvider = new CArrayDataProvider($model->changes);
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns'=>array(
'name',
),
));
}
Share this topic:
Page 1 of 1

Help











