I have used Gii to create models/CRUD classes. I have a master-detail relationship in my model, where "…each employee has 0 or more tasks…". Within my Employee model I have the following method:
public function getAllEmployeesAndTasks()
{
return $this->model()->with('tasks')->findAll();
}
I want to display the results in a view so that the employee’s name is displayed as a heading, and then the list of tasks for that employee is displayed. For example:
Employee 1
Task 1 for employee 1
Task 2 for employee 1
Task 3 for employee 1
Employee 2
Task 1 for employee 2
Task 2 for employee 2
Task ... for employee 2
Employee 3
Task 1 for employee 3
Task 2 for employee 3
Task ... for employee 3
How can I achieve this?
Would I have to manually use loop/foreach constructs within the view?
Would it be possible to use zii.widgets.grid.CGridView to list the tasks for each employee?
Should I approach it by spending the time designing and implementing my own widget?
Any guidance/pointers on the best way to achieve this would be much appreciated.
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider, // this data for master
'itemView'=>'_viewdetail', // refers to the partial view named '_viewdetail'
'viewData'=>array('data'=>$datadetail), // this data for view detail
));