backend/controllers/TermRelationshipController.php
/**
     * If user change the value of checkbox when updating a post, this action will be triggered.
     * If the checkbox checked it will trigger addItem (create TermRelationship) while if unchecked will trigger
     * remItem (remove TermRelationship).
     *
     * @throws \Exception
     * @throws \yii\web\NotFoundHttpException
     */
If user change the value of checkbox when updating a post, this action will be triggered.
If the checkbox checked it will trigger addItem (create TermRelationship) while if unchecked will trigger
remItem (remove TermRelationship).

@throws \Exception
@throws \yii\web\NotFoundHttpException
If user change the value of checkbox when updating a post this action will be triggered . If the checkbox checked it will trigger addItem ( create TermRelationship ) while if unchecked will trigger remItem ( remove TermRelationship ) . @throws \ Exception @throws \ yii \ web \ NotFoundHttpException
public function actionAjaxChangeHierarchical()
    {
        if (Yii::$app->request->post('action') === 'addItem') {
            $model = new TermRelationship();
            $model->load(Yii::$app->request->post());
            if ($model->save()) {
                if ($term = $this->findTerm($model->term_id)) {
                    $term->updateAttributes(['count' => ++$term->count]);
                }
            }
        } elseif (Yii::$app->request->post('action') === 'remItem'
            && $termRelationship = Yii::$app->request->post('TermRelationship')
        ) {
            $model = $this->findModel($termRelationship['post_id'], $termRelationship['term_id']);
            if ($model->delete()) {
                if ($term = $this->findTerm($model->term_id)) {
                    $term->updateAttributes(['count' => --$term->count]);
                }
            }
        }
    }
public function actionAjaxChangeHierarchical ( ) { if ( Yii :: $ app -> request -> post ( 'action' ) === 'addItem' ) { $ model = new TermRelationship ( ) ; $ model -> load ( Yii :: $ app -> request -> post ( ) ) ; if ( $ model -> save ( ) ) { if ( $ term = $ this -> findTerm ( $ model -> term_id ) ) { $ term -> updateAttributes ( [ 'count' => ++ $ term -> count ] ) ; } } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === 'remItem' && $ termRelationship = Yii :: $ app -> request -> post ( 'TermRelationship' ) ) { $ model = $ this -> findModel ( $ termRelationship [ 'post_id' ] , $ termRelationship [ 'term_id' ] ) ; if ( $ model -> delete ( ) ) { if ( $ term = $ this -> findTerm ( $ model -> term_id ) ) { $ term -> updateAttributes ( [ 'count' => -- $ term -> count ] ) ; } } } }
If user change the value of checkbox when updating a post, this action will be triggered.
If user change the value of checkbox when updating a post this action will be triggered .