Blame view

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