This is a very general question and I’m hoping someone can enlighten me as to the possible approaches to this situation within the context of Yii. I’m not exactly sure how to explain this, so please bear with me. Any thoughts would be appreciated.
Here’s the situation: I’m building a small app for students to publish portfolios.
To do this, I need to have Courses and Users. But there are two types of Users, Students and Teachers.
When I first started this, I made a single database table (User) with an IS_STUDENT boolean field. But within the application, I don’t want people to think about “Users”. I want to treat Teachers and Students like totally different object types.
I could create a separate database table for each (Teacher & Student) and CRUD them entirely separately. But then I run into the problem of logging in, where I don’t know what table to look in to match their credentials (I’m thinking of the UserIdentity.php file).
So now I’m contemplating how much sense it makes to have basically twice as many methods in the User model class (eg. actionCreateStudent, actionCreateTeacher, actionListStudents, actionViewTeacher, etc). I am also questioning whether to create double the amount of view scripts (viewTeacher.php, viewStudent.php, _formStudent.php) or just pass some kind of IS_STUDENT variable to the view.php file and change labels and various other items within the same script file.
I’m sorry for just dumping all this out there, but I’m really hoping to learn something from this. I mention inheritance in the subject because I feel like if I was doing a traditional application, I would be definitely make use of this, with an abstract User class leading to a Student and a Teacher class. This would make perfect sense there, but within the context of a database-driven web app and Yii, I’m not sure what makes the most sense.
Like I said, I look forward to any ideas as to the best practices in this situation.
Thanks a lot guys,