e.g. model Class , model Students (Class HasMany Students ) relation
I want to display ‘Class’ model in CgridView (all classes) with on of the columns is studentsNames as a dropdown for example or any other way u find it more confient
// in Class.php
/* returns the students' names joined by \n */
public function getStudentNames()
{
$names = array();
foreach($this->students as $student) {
$names[] = $student->name;
}
return implode("\n", $names);
}
// in View
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'class-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
...
array(
'name' => 'students.name',
'type' => 'ntext',
'value' => '$data->studentNames',
),
...
Probably you already know that, and don’t like the row to be very tall with many sutudents’ names …
There should be many other ways to display the related HAS_MANY model objects. I don’t think there’s a standard way for doing it.
Well, but I don’t think it’s a good idea to use dropDownList just for displaying data. It should be confusing to the users, because the dropDownList is expected to be an input element.