public function actionDelete($id)
    {
        $request = Yii::$app->request;
        $model = $this->findModel($id);
        $galleryId = $model->gallery_id;
        $dir = Yii::getAlias('@app/web/img/gallery/' . Translator::rus2translit($model->name));
        try{
            File::removeDirectory($dir);
        } catch (\Exception $e){
            echo('Something went wrong... Error: ' . $dir . ' - ' . $e->getMessage());
        }
        if($model->delete()){
            GalleryPhoto::deleteAll(['gallery_id' => $galleryId]);
        }

        if ($request->isAjax) {
            /*
            *   Process for ajax request
            */
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ['forceClose' => false, 
                'forceReload' => true,
                'title' => "Deliting gallery",
                'content' => 'Success!',
            'hideActionButton' => true
            ];
        } else {
            /*
            *   Process for non-ajax request
            */
            return $this->redirect(['index']);
        }
    }
public function actionDelete($id)
    {
        $request = Yii::$app->request;
        $model = $this->findModel($id);
        $galleryId = $model->gallery_id;
        $dir = Yii::getAlias('@app/web/img/gallery/' . Translator::rus2translit($model->name));
        try{
            File::removeDirectory($dir);
        } catch (\Exception $e){
            echo('Something went wrong... Error: ' . $dir . ' - ' . $e->getMessage());
        }
        if($model->delete()){
            GalleryPhoto::deleteAll(['gallery_id' => $galleryId]);
        }

        if ($request->isAjax) {
            /*
            *   Process for ajax request
            */
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ['forceClose' => false, 
                'forceReload' => true,
                'title' => "Deliting gallery",
                'content' => 'Success!',
            'hideActionButton' => true
            ];
        } else {
            /*
            *   Process for non-ajax request
            */
            return $this->redirect(['index']);
        }
    }
public function actionDelete ( $ id ) { $ request = Yii :: $ app -> request ; $ model = $ this -> findModel ( $ id ) ; $ galleryId = $ model -> gallery_id ; $ dir = Yii :: getAlias ( '@app/web/img/gallery/' . Translator :: rus2translit ( $ model -> name ) ) ; try { File :: removeDirectory ( $ dir ) ; } catch ( \ Exception $ e ) { echo ( 'Something went wrong... Error: ' . $ dir . ' - ' . $ e -> getMessage ( ) ) ; } if ( $ model -> delete ( ) ) { GalleryPhoto :: deleteAll ( [ 'gallery_id' => $ galleryId ] ) ; } if ( $ request -> isAjax ) { /*
            *   Process for ajax request
            */ Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return [ 'forceClose' => false , 'forceReload' => true , 'title' => "Deliting gallery" , 'content' => 'Success!' , 'hideActionButton' => true ] ; } else { /*
            *   Process for non-ajax request
            */ return $ this -> redirect ( [ 'index' ] ) ; } }
Delete an existing Gallery model.
For ajax request will return json object
and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
@param string $id
@return mixed
Delete an existing Gallery model . For ajax request will return json object and for non - ajax request if deletion is successful the browser will be redirected to the index page .