controllers/CategoryController.php
/**
     * Deletes an existing Category model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Deletes an existing Category model.
If deletion is successful, the browser will be redirected to the 'index' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Deletes an existing Category model . If deletion is successful the browser will be redirected to the ' index ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionDelete($id)
    {
        $category = $this->findModel($id);
        if (Category::find()->where(['parent_id' => $id])->count() == 0){
            if (Product::find()->where(['category_id' => $id])->count() > 0) {
                Yii::$app->session->setFlash('error', "This category has products. At first You have to remove products.");
            } else {
                $category -> delete();
            }
        } else
        {
            Yii::$app->session->setFlash('error', "This category has sub categories. At first You have to remove them");
        }
        return $this->redirect(['index']);
    }
public function actionDelete ( $ id ) { $ category = $ this -> findModel ( $ id ) ; if ( Category :: find ( ) -> where ( [ 'parent_id' => $ id ] ) -> count ( ) == 0 ) { if ( Product :: find ( ) -> where ( [ 'category_id' => $ id ] ) -> count ( ) > 0 ) { Yii :: $ app -> session -> setFlash ( 'error' , " This category has products. At first You have to remove products. " ) ; } else { $ category -> delete ( ) ; } } else { Yii :: $ app -> session -> setFlash ( 'error' , " This category has sub categories. At first You have to remove them " ) ; } return $ this -> redirect ( [ 'index' ] ) ; }
Deletes an existing Category model.
Deletes an existing Category model .