Hello,
I’ve just started learning Yii, and am currently stuck with the following problem.
I have a tables Task and Solution with the following relation
'solutions' => array(self::HAS_MANY, 'Solution', 'task_id')
In "view" page for Task I have added a GridView that would list all related solutions (i.e. all solutions for that task) by setting an ActiveDataProvider that would fetch items by column value. That GridView is sortable, but I would also like to be able to filter it.
I can see that in “admin” a filter is added just by “‘filter’=>$model”, but since I use my own ActiveDataProvider, and $model would refer to the wrong model I’m not too sure how to proceed.
Here is the related code from Task view
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'topic.name',
'difficulty',
'description',
),
)); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>new CActiveDataProvider("Test",array
(
'criteria'=>array('condition'=>'task_id='.$model->id)
)),
'columns'=>array(
'input',
'output',
),
)); ?>
//this needs a filter
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>new CActiveDataProvider("Solution",array
(
'criteria'=>array('condition'=>'task_id='.$model->id)
)),
'columns'=>array(
'student_id',
'attempt_count',
'last_attempt',
'is_solved:boolean',
),
)); ?>