title: Code Igniter relationships
body: <p>I'm starting to learn the PHP Code Igniter framework and I have a pretty basic question and I'm having problems finding some good sample code on the web.</p>
  
  <p>Let's say I have 2 simple database tables (teacher and student).  Each has a unique identifier field (t_id and s_id).  Every student has a teacher so there is a s_t_id field in the student table which represents which teacher the student has.</p>
  
  <p>I want to have a screen that lists all of the teachers with their students underneath.  Kind of like the teacher is a heading and the students belonging to that teacher are subheadings.</p>
  
  <p>I think I could do this, but I'm not sure if this is the proper way to do it or is it more of a hack?</p>
  
  <p>I have a model for the teacher and the student and each has a controller.</p>
  
  <p>But I load all of the data for both of them in the view for the teacher.  So my teacher controller code is something like this:</p>
  
  <pre><code>$data['teachers'] = $this-&gt;teachers_model-&gt;get_teachers();
  $data['students'] = $this-&gt;students_model-&gt;get_students();
  </code></pre>
  
  <p>In my view, I just loop thru the teachers and get the students for each teacher in each iteration from the array passed to the view.</p>
  
  <p>Does this seem like the proper way to do this following MVC patterns?  Or is this just a hack?  It seems kind of awkward to me to load the students in the controller for the teachers.</p>