I have two tables - ‘teachers’ and ‘students’ joined in a many-to-many relationship via a 3rd table ‘TeachersHasStudents’.
I’ve used 2 foreach loops to build an array of all the student objects belonging to the currently logged in teacher.
// the models to work with
$teachers = Teachers::model()->findAll($condition="teacher_id='$userId'");
$students = Students::model()->findAll();
foreach($teachers as $teacher)
{
// get all students for this teacher
foreach($teacher->students as $student)
{
echo $student->student_name_first . "<br />"; // works - echo's each name
// build array
$rawData=array($student);
}
}
echo $rawData[0]['student_name_first']; //works - echo's the name of first student in the array
// build dataProvider - the bit I'm stuck on??
$dataProvider=new CArrayDataProvider($rawData);
I want to display them using the CListView widget - which dataProvider should I use and how would I set it up?
Thanks in advance for any help
O