Insert Data To A Table From Two Non-Related Tables

Hi All,

I have only two weeks experience in yii.

My situation is like this.

I have three tables student, class and attendance. student and class tables are not related, But attendance table contain student_id and class_id.

I want to create a view to select attended students to a selected class as follows;

  1. Select a class from list. ( Table: class)

  2. Select students by checkbox list.( Table: Student)

  3. Update the attendance table by class_id and selected student_ids.

  4. Avoid duplication of class_id, student_id combination in attendance table.

It’s really appreciate any help to create relevant MVC pages.

So far I checked following pages, but still failed to solve the situation.

Thanks for any support.

That’s MANY_MANY relation ( )

Unfortunately, Yii itself cannot store MANY_MANY, but there are a lot of extensions

Dear Orey,

Thank you very much for the quick reply.

I tried to use the extension multimodelforms before. It didn’t meet with my requirements.

I never thought about such a big list of extensions until your suggestion. Thanks for that and I’ll try them.

Actually my biggest problem is, " How to post (from view) and get (in controller) two data columns. ( class_id is only one record while student_id will be more than one at a time).

Check out this post on how to display many-many checkboxes. This technique uses cadvancedarbehavior.


Thank you very much.

This is a life saver. Worked like charm.

Another two questions:

  1. How to add an extra column to checkbox list ( Eg: Name,Gender)?

  2. Can’t we do pagination and search for this checbox list?