/** * Create MenuItem models. * * @param int $id */ public function actionCreateMenuItem($id) { if (Yii::$app->request->post('type') === 'link') { $model = new MenuItem(); $model->menu_id = $id; if ($model->load(Yii::$app->request->post()) && $model->save()) { echo $this->renderPartial('_render-item', ['item' => $model, 'wrapper' => 'true']); } } elseif (Yii::$app->request->post('type') === 'post' && ($postIds = Yii::$app->request->post('postIds'))) { foreach ($postIds as $postId) { if ($postModel = $this->findPost($postId)) { $model = new MenuItem(); $model->setAttributes(['menu_id' => $id, 'menu_label' => $postModel->post_title, 'menu_url' => $postModel->getUrl()]); if ($model->save()) { echo $this->renderPartial('_render-item', ['item' => $model, 'wrapper' => 'true']); } } } } elseif (Yii::$app->request->post('type') === 'taxonomy' && ($termIds = Yii::$app->request->post('termIds'))) { foreach ($termIds as $termId) { if ($termModel = $this->findTerm($termId)) { $model = new MenuItem(); $model->setAttributes(['menu_id' => $id, 'menu_label' => $termModel->term_name, 'menu_url' => $termModel->getUrl()]); if ($model->save()) { echo $this->renderPartial('_render-item', ['item' => $model, 'wrapper' => 'true']); } } } } }