Welcome Guest, Not a member yet? Register   Sign In
Basic question about setting up models, views, and controllers.
#1

[eluser]Unknown[/eluser]
I'm new to CodeIgniter and have a question. I followed the tutorial on this site, but it didn't get very complex.

I'm trying to find out how I can set up the model/view/controller for the following situation:

I have 2 models/database tables, teacher and student. Each teacher is represented by a row in the db. Each student has a teacher which is indicated by a field on the student table.

I want to create a view that lists all of the teachers with all of the students. But all of the students will be grouped under the teacher in which they belong.

For example the view will look something like this:
Teacher 1
Student 1
Student 2
Student 3
Teacher 2
Student 4
Student 5
Teacher 3
Student 6
Student 7
Teacher 4
Student 8

Currently I have something like this in my teacher controller:

Code:
$data['teachers'] = $this->teachers_model->get_teachers();
$data['students'] = $this->students_model->get_students();

And then in the view I would just iterate through each teacher and then get the students based upon the current iteration.

I guess I can eventually get it to work this way, but does this meet up to coding standards, etc. Should I really be loading student data from the teacher controller?

So what is the proper way to set something like this up using CI?




Theme © iAndrew 2016 - Forum software by © MyBB