/** * Ajax to create term-relationship triggered when the user add new item in selectize box. */ public function actionAjaxCreateNonHierarchical() { $model = new TermRelationship(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($term = $this->findTerm($model->term_id)) { $term->term_count++; $term->save(); } } }
/** * Create term taxonomy non-hierarchical */ public function actionAjaxCreateHierarchical() { $term = new Term(); $termRelationship = new TermRelationship(); if ($term->load(Yii::$app->request->post())) { if ($termRelationship->load(Yii::$app->request->post()) && $termRelationship->post_id) { $term->term_count = 1; if ($term->save()) { $termRelationship->term_id = $term->id; if ($termRelationship->save()) { echo '<br />'; echo Html::label(Html::checkbox('termIds', true, ['value' => $term->id, 'class' => 'new-i-check']) . ' ' . $term->term_name); } } } else { if ($term->save()) { echo '<br />'; echo Html::label(Html::checkbox('termIds', true, ['value' => $term->id]) . $term->term_name); } } } }