From 5707ae7a9f75282dcc87067d6d362e1d9b2b2358 Mon Sep 17 00:00:00 2001 From: vova Date: Thu, 7 Apr 2022 17:44:52 +0300 Subject: [PATCH] tiles admin controller --- backend/controllers/TileController.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/TileLang.php | 3 +-- 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 backend/controllers/TileController.php diff --git a/backend/controllers/TileController.php b/backend/controllers/TileController.php new file mode 100644 index 0000000..7234bf2 --- /dev/null +++ b/backend/controllers/TileController.php @@ -0,0 +1,60 @@ +generateLangs(); + + if ($model->loadWithLangs(\Yii::$app->request)) { + if ($model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + } + public function actionView($id): string + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + protected function findModel($id): Tile + { + if (($model = Tile::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} \ No newline at end of file diff --git a/common/models/TileLang.php b/common/models/TileLang.php index 3fe4f74..2303715 100644 --- a/common/models/TileLang.php +++ b/common/models/TileLang.php @@ -4,7 +4,6 @@ namespace common\models; use artbox\core\models\Image; use artbox\core\models\Language; -use artbox\core\models\Slide; use yii\db\ActiveRecord; class TileLang extends ActiveRecord @@ -55,7 +54,7 @@ class TileLang extends ActiveRecord 'targetAttribute' => [ 'language_id' => 'id' ], ], [ - [ 'slide_id' ], + [ 'tile_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Tile::className(), -- libgit2 0.21.4