public function actionDelete($id)
    {
        if (!\Yii::$app->user->can('delete'))
            throw new ForbiddenHttpException(Module::t('core', 'Access denied.'));

        if($id == 1)
            \Yii::$app->session->setFlash(
                'warning',
                \Yii::t('core', 'Node can not be deleted.')
            );
        else {
            $node = $this->findModel($id);
            // find all node childrens
            $childrens = $node->children()->all();
            $node->deleteWithChildren();
            // update deleted rubrics to 1 in all posts with rubrics are $id or $childrens ID
            $ids = $id;
            foreach($childrens as $node)
                $ids .= ',' . $node->id;
            Post::updateAll(['rubric' => 1], 'rubric IN (' . $ids . ')');
        }

        return $this->redirect(['index']);
    }
public function actionDelete($id)
    {
        if (!\Yii::$app->user->can('delete'))
            throw new ForbiddenHttpException(Module::t('core', 'Access denied.'));

        if($id == 1)
            \Yii::$app->session->setFlash(
                'warning',
                \Yii::t('core', 'Node can not be deleted.')
            );
        else {
            $node = $this->findModel($id);
            // find all node childrens
            $childrens = $node->children()->all();
            $node->deleteWithChildren();
            // update deleted rubrics to 1 in all posts with rubrics are $id or $childrens ID
            $ids = $id;
            foreach($childrens as $node)
                $ids .= ',' . $node->id;
            Post::updateAll(['rubric' => 1], 'rubric IN (' . $ids . ')');
        }

        return $this->redirect(['index']);
    }
public function actionDelete ( $ id ) { if ( ! \ Yii :: $ app -> user -> can ( 'delete' ) ) throw new ForbiddenHttpException ( Module :: t ( 'core' , 'Access denied.' ) ) ; if ( $ id == 1 ) \ Yii :: $ app -> session -> setFlash ( 'warning' , \ Yii :: t ( 'core' , 'Node can not be deleted.' ) ) ; else { $ node = $ this -> findModel ( $ id ) ; // find all node childrens $ childrens = $ node -> children ( ) -> all ( ) ; $ node -> deleteWithChildren ( ) ; // update deleted rubrics to 1 in all posts with rubrics are $id or $childrens ID $ ids = $ id ; foreach ( $ childrens as $ node ) $ ids .= ',' . $ node -> id ; Post :: updateAll ( [ 'rubric' => 1 ] , 'rubric IN (' . $ ids . ')' ) ; } return $ this -> redirect ( [ 'index' ] ) ; }
Deletes an existing Rubric model.
If deletion is successful, the browser will be redirected to the 'index' page.
@param integer $id
@return mixed
Deletes an existing Rubric model . If deletion is successful the browser will be redirected to the index page .