|
@@ 96-110 (lines=15) @@
|
| 93 |
|
$model = new PostType(); |
| 94 |
|
$taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'name'); |
| 95 |
|
|
| 96 |
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 97 |
|
$postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy'); |
| 98 |
|
if ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds'])) { |
| 99 |
|
foreach ($taxonomyIds as $taxonomyId) { |
| 100 |
|
$postTypeTaxonomy = new PostTypeTaxonomy(); |
| 101 |
|
$postTypeTaxonomy->setAttributes([ |
| 102 |
|
'post_type_id' => $model->id, |
| 103 |
|
'taxonomy_id' => $taxonomyId, |
| 104 |
|
]); |
| 105 |
|
$postTypeTaxonomy->save(); |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
return $this->redirect(['view', 'id' => $model->id]); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
return $this->render('create', [ |
| 113 |
|
'model' => $model, |
|
@@ 131-146 (lines=16) @@
|
| 128 |
|
$model = $this->findModel($id); |
| 129 |
|
$taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'name'); |
| 130 |
|
|
| 131 |
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 132 |
|
PostTypeTaxonomy::deleteAll(['post_type_id' => $id]); |
| 133 |
|
$postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy'); |
| 134 |
|
if ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds'])) { |
| 135 |
|
foreach ($taxonomyIds as $taxonomyId) { |
| 136 |
|
$postTypeTaxonomy = new PostTypeTaxonomy(); |
| 137 |
|
$postTypeTaxonomy->setAttributes([ |
| 138 |
|
'post_type_id' => $model->id, |
| 139 |
|
'taxonomy_id' => $taxonomyId, |
| 140 |
|
]); |
| 141 |
|
$postTypeTaxonomy->save(); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
return $this->redirect(['view', 'id' => $model->id]); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
return $this->render('update', [ |
| 149 |
|
'model' => $model, |