Blame view

frontend/modules/page/controllers/PageController.php 1.84 KB
d1f8bd40   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  <?php
  
  namespace frontend\modules\page\controllers;
  
  use Yii;
  use yii\filters\VerbFilter;
  use yii\web\NotFoundHttpException;
  
  //
  use thread\actions\RecordView;
  //
  use frontend\components\BaseController;
  use frontend\modules\page\models\Page;
  
  /**
   * Class PageController
   *
   * @package frontend\modules\page\controllers
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class PageController extends BaseController
  {
      public $title = "Page";
      public $layout = "@app/layouts/base";
      public $defaultAction = 'index';
  
      /**
       *
       */
      public function init()
      {
          parent::init();
  
          $this->breadcrumbs = [
              [
                  'label' => Yii::t('page', 'Pages')
              ]
          ];
      }
  
      /**
       * @return array
       */
      public function behaviors()
      {
          return [
              'verbs' => [
                  'class' => VerbFilter::class,
                  'actions' => [
                      'index' => ['get'],
                      'contacts' => ['get'],
                      'view' => ['get'],
                  ],
              ]
          ];
      }
  
      /**
       * @return array
       */
      public function actions()
      {
          $page = Page::findByAlias(Yii::$app->request->get('alias', ''))->asArray()->one();
          if(($page) && $page['id'] == Page::RESULT_PAGE_ID && Yii::$app->getUser()->isGuest){
              throw new NotFoundHttpException();
          }
          return [
              'view' => [
                  'class' => RecordView::class,
                  'modelClass' => Page::class,
                  'methodName' => 'getByAlias',
                  'layout' => '@app/layouts/base'
              ]
          ];
      }
  
      /**
       *
       * @return string
       */
      public function actionIndex()
      {
          $this->layout = "/start";
          return $this->run('view', ['alias' => 'start']);
      }
  
  
  }