I am totally new in Yii framework and quite frankly do not know everything about it. I have an ongoing project in which I am stuck in a problem.
I have 3 tables in the project. Here are the table names and the rows:
-
Users (id, name, email, username, password, currentTIme) Uses for storing user information.
-
Groups (id, name, currentTIme) Uses for storing Group Information.
-
UserGroup (id, userId, groupId, currentTime) Uses for keeping the relation between user and group.
Now, what I have to do is after creating 3 models, Users and Groups model will be used for all users. Different groups was added like:
- CSE 02. EEE 03. BBA 04. Architecture etc. etc.
Now, when ‘User create’ portion 2 things have to happen. One, the group names (CSE, EEE, BBA, Architecture etc.) will be shown in a listbox to choose along with the user’s other information (name, password etc.). Now question is How I can show the name of Groups in a listbox in the model Users where there is no relationship.
Second problem is, when I will click ‘submit’ it will update 2 tables ‘Users’ and ‘UserGroup’. Name, password,currentTime will be saved in ‘User’ and userid(of current user), groupid(id of the groups user will be selected like 1 for CSE etc.) will be saved in ‘UserGroup’ table.
Thank you for tolerating my horrible English and any kind of comment/feedback will be a big help for me…..Thanks in advance
I found out answer of the first part which shows the list from another model. For anybody like me, it can be useful i am posting it here.
in the /models/users.php:
class Users extends CActiveRecord
{
public $Groups;
…………………..
…………………..
}
in the /view/users/_form.php: