Blame view

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