/** * Creates a new PostType and PostTypeTaxonomy model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new PostType(); $taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'taxonomy_name'); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (($postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy')) && ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomy_ids']))) { foreach ($taxonomyIds as $taxonomy_id) { $postTypeTaxonomy = new PostTypeTaxonomy(); $postTypeTaxonomy->post_type_id = $model->id; $postTypeTaxonomy->taxonomy_id = $taxonomy_id; $postTypeTaxonomy->save(); } } return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', ['model' => $model, 'taxonomy' => new Taxonomy(), 'taxonomies' => $taxonomies]); }