Revision #11 has been created by softark on Mar 15, 2018, 2:00:39 AM with the memo:
error in sample code fixed
« previous (#10) next (#12) »
Changes
Title
unchanged
How to create/update a model with its related items using Listbox or CheckboxList
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
listBox checkboxList
Content
changed
[...]
/* clear the categories of the post before saving */
PostCategory::deleteAll(['post_id' => $this->id]);
if (is_array($this->category_ids)) {
foreach($this->category_ids as $category_id) {
$pc = new PostCategory();
$pc->post_id = $this->post_id;
$pc->category_id = $category_id;
$pc->save();
}
}
/* Be careful, $this->category_ids can be empty */[...]