Hi guys! I’m new to Yii and today I couldn’t solve the following problem.
I have the following table structure
post
|-----|--------|
| id | title |
|-----|--------|
category
|-----|---------|
| id | name |
|-----|---------|
| 1 | cat1 |
|-----|---------|
| 2 | cat2 |
|-----|---------|
| 3 | cat3 |
|-----|---------|
| 4 | cat4 |
|-----|---------|
post_category (Primary key (post_id, category_id))
|----------|---------------|
| post_id | category_id |
|----------|---------------|
I want the following CRUD form for my Post table(model):
-
The form should include textField for Post->title
-
The form should also include checkBoxList populated from Category->id and Category->name;
-
Submit button.
Then on submit(create) my tables should be filled like these:
Post
|-----|--------|
| id | title |
|-----|--------|
| 1 | title1 |
|-----|--------|
category (does not change)
|-----|--------|
| id | name |
|-----|--------|
| 1 | cat1 |
|-----|--------|
| 2 | cat2 |
|-----|--------|
| 3 | cat3 |
|-----|--------|
| 4 | cat4 |
|-----|--------|
post_category (assuming that I checked all checkboxes)
|----------|---------------|
| post_id | category_id |
|----------|---------------|
| 1 | 1 |
|----------|---------------|
| 1 | 2 |
|----------|---------------|
| 1 | 3 |
|----------|---------------|
| 1 | 4 |
|----------|---------------|
(Sorry , wysiwyg is not displaying my tables correctly . I hope you get the idea )
I think I have to use mysql transactions to insert data into two tables. But still I dont know how to update post and change the categories it belongs to. And I dont know how to generate the form I want. Please help. Thanks