Blame view

frontend/controllers/PersoneController.php 1.6 KB
e75f2ac9   Alexey Boroda   -Doctor pages fro...
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
  <?php
      
      namespace frontend\controllers;
      
      use common\models\Persone;
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
  
      /**
       * Class PersoneController
       *
       * @package frontend\controllers
       */
      class PersoneController extends Controller
      {
          /**
           * @return string
           */
          public function actionIndex()
          {
              $persones = Persone::find()
                                 ->with('lang.alias')
                                 ->all();
              
              return $this->render(
                  'index',
                  [
                      'persones' => $persones,
                  ]
              );
          }
          
          /**
           * @param int $id
           *
           * @return string
           */
          public function actionView(int $id)
          {
              $model = $this->findModel($id);
              
              return $this->render(
                  'view',
                  [
                      'model' => $model,
                  ]
              );
          }
          
          /**
           * @param $id
           *
           * @return array|null|\yii\db\ActiveRecord
           * @throws \yii\web\NotFoundHttpException
           */
          protected function findModel($id)
          {
              $model = Persone::find()
                              ->with('lang.alias')
                              ->where([ 'id' => $id ])
                              ->one();
              
              if (empty($model)) {
                  throw new NotFoundHttpException();
              } else {
                  return $model;
              }
          }
      }