I have a model with has_many association.
Let's just say Student has many Courses.
I'd like to show all courses of a particular student using CGridView.
Something like this:
$this->widget('zii.widgets.grid.CGridView', array(                                                 
  'dataProvider' => $model->courses,                                                             
  'columns'=>array(                                                                                                                                                                            
    'name',                                                                                                                                                                                  
  ),                                                                                                 
));
Also tried new CActiveDataProvider($model->courses) as dataProvider but still wont work.
Is there an easy way to do this? Or do I have to create a search criteria on the Course model with some criteria taken from the student model manually?
Get rid of the parentheses after courses
Use an arraydataprovider
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider' => new CArrayDataProvider($model->courses, array()),
  'columns'=>array(
    'name',
  ), 
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With