Commit 5707ae7a9f75282dcc87067d6d362e1d9b2b2358
1 parent
19265dc6
tiles admin controller
Showing
2 changed files
with
61 additions
and
2 deletions
Show diff stats
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace backend\controllers; | |
| 4 | + | |
| 5 | +use common\models\Tile; | |
| 6 | +use yii\web\Controller; | |
| 7 | +use yii\web\NotFoundHttpException; | |
| 8 | + | |
| 9 | +class TileController extends Controller | |
| 10 | +{ | |
| 11 | + /** | |
| 12 | + * Creates a new Tile model. | |
| 13 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 14 | + * @return mixed | |
| 15 | + */ | |
| 16 | + public function actionCreate() | |
| 17 | + { | |
| 18 | + $model = new Tile(); | |
| 19 | + $model->generateLangs(); | |
| 20 | + | |
| 21 | + if ($model->loadWithLangs(\Yii::$app->request)) { | |
| 22 | + if ($model->saveWithLangs()) { | |
| 23 | + return $this->redirect( | |
| 24 | + [ | |
| 25 | + 'view', | |
| 26 | + 'id' => $model->id, | |
| 27 | + ] | |
| 28 | + ); | |
| 29 | + } | |
| 30 | + } | |
| 31 | + return $this->render( | |
| 32 | + 'create', | |
| 33 | + [ | |
| 34 | + 'model' => $model, | |
| 35 | + 'modelLangs' => $model->modelLangs, | |
| 36 | + ] | |
| 37 | + ); | |
| 38 | + } | |
| 39 | + public function actionView($id): string | |
| 40 | + { | |
| 41 | + return $this->render('view', [ | |
| 42 | + 'model' => $this->findModel($id), | |
| 43 | + ]); | |
| 44 | + } | |
| 45 | + public function actionDelete($id) | |
| 46 | + { | |
| 47 | + $this->findModel($id)->delete(); | |
| 48 | + | |
| 49 | + return $this->redirect(['index']); | |
| 50 | + } | |
| 51 | + | |
| 52 | + protected function findModel($id): Tile | |
| 53 | + { | |
| 54 | + if (($model = Tile::findOne($id)) !== null) { | |
| 55 | + return $model; | |
| 56 | + } else { | |
| 57 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
common/models/TileLang.php
| ... | ... | @@ -4,7 +4,6 @@ namespace common\models; |
| 4 | 4 | |
| 5 | 5 | use artbox\core\models\Image; |
| 6 | 6 | use artbox\core\models\Language; |
| 7 | -use artbox\core\models\Slide; | |
| 8 | 7 | use yii\db\ActiveRecord; |
| 9 | 8 | |
| 10 | 9 | class TileLang extends ActiveRecord |
| ... | ... | @@ -55,7 +54,7 @@ class TileLang extends ActiveRecord |
| 55 | 54 | 'targetAttribute' => [ 'language_id' => 'id' ], |
| 56 | 55 | ], |
| 57 | 56 | [ |
| 58 | - [ 'slide_id' ], | |
| 57 | + [ 'tile_id' ], | |
| 59 | 58 | 'exist', |
| 60 | 59 | 'skipOnError' => true, |
| 61 | 60 | 'targetClass' => Tile::className(), | ... | ... |