Blame view

frontend/controllers/PageController.php 1.92 KB
f3b6b9b1   Alexey Boroda   -Seo component in...
1
2
  <?php
      namespace frontend\controllers;
8596ef4b   Alexey Boroda   -Seo component ready
3
4
  
      use artbox\core\components\SeoComponent;
f3b6b9b1   Alexey Boroda   -Seo component in...
5
      use artbox\core\models\Page;
f3b6b9b1   Alexey Boroda   -Seo component in...
6
7
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
8596ef4b   Alexey Boroda   -Seo component ready
8
9
      use Yii;
  
f3b6b9b1   Alexey Boroda   -Seo component in...
10
11
12
13
14
15
16
17
18
19
      /**
       * Class PageController
       *
       * @package frontend\controllers
       */
      class PageController extends Controller
      {
          public function actionView($id)
          {
              $model = $this->findModel($id);
4acbd19d   Alexey Boroda   -Bar tabs
20
      
8596ef4b   Alexey Boroda   -Seo component ready
21
22
23
24
25
              /**
               * @var SeoComponent $seo
               */
              $seo = Yii::$app->get('seo');
              $seo->setModel($model->lang);
4acbd19d   Alexey Boroda   -Bar tabs
26
27
28
      
              $pages = Page::find()
                           ->with('lang')
6e516b40   Yarik   Layout complete
29
30
31
32
33
34
35
                           ->where(
                               [
                                   'not',
                                   [ 'id' => $id ],
                               ]
                           )
                           ->limit(5)
4acbd19d   Alexey Boroda   -Bar tabs
36
37
                           ->all();
              
f3b6b9b1   Alexey Boroda   -Seo component in...
38
39
40
41
              return $this->render(
                  'view',
                  [
                      'model' => $model,
4acbd19d   Alexey Boroda   -Bar tabs
42
                      'pages' => $pages,
eacd7080   Alexey Boroda   -Gallery ready
43
                      'images' => $model->getImages(),
f3b6b9b1   Alexey Boroda   -Seo component in...
44
45
46
                  ]
              );
          }
8596ef4b   Alexey Boroda   -Seo component ready
47
      
f3b6b9b1   Alexey Boroda   -Seo component in...
48
49
          protected function findModel($id)
          {
8596ef4b   Alexey Boroda   -Seo component ready
50
51
52
53
54
55
56
57
58
59
60
              /**
               * @var Page $model
               */
              $model = Page::find()
                           ->where(
                               [
                                   'id' => $id,
                               ]
                           )
                           ->with('lang')
                           ->one();
4acbd19d   Alexey Boroda   -Bar tabs
61
      
6e516b40   Yarik   Layout complete
62
              if (!empty( $model )) {
8596ef4b   Alexey Boroda   -Seo component ready
63
64
65
                  if ($model->lang->alias_id !== Yii::$app->seo->aliasId) {
                      throw new NotFoundHttpException('Wrong language');
                  }
f3b6b9b1   Alexey Boroda   -Seo component in...
66
67
68
69
70
71
                  return $model;
              } else {
                  throw new NotFoundHttpException('Model not found');
              }
          }
      }