OSDN Git Service

Внесены исправления в алгоритм формирования стартовой страницы. Внесены коррективы...
[invent/invent.git] / controllers / RegionsController.php
1 <?php
2
3 namespace app\controllers;
4
5 use Yii;
6 use app\models\Regions;
7 use app\models\RegionsSearch;
8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter;
11
12 /**
13  * RegionsController implements the CRUD actions for Regions model.
14  */
15 class RegionsController extends Controller
16 {
17     /**
18      * {@inheritdoc}
19      */
20     public function behaviors()
21     {
22         return [
23             'verbs' => [
24                 'class' => VerbFilter::className(),
25                 'actions' => [
26                     'delete' => ['POST'],
27                 ],
28             ],
29         ];
30     }
31
32     /**
33      * Список всех регионов/подразделений.
34      * @return mixed
35      */
36     public function actionIndex()
37     {
38         $searchModel = new RegionsSearch();
39         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
40
41         return $this->render('index', [
42             'searchModel' => $searchModel,
43             'dataProvider' => $dataProvider,
44         ]);
45     }
46
47     /**
48      * Плказ одного региона/подразделения (не используется).
49      * @param integer $id
50      * @return mixed
51      * @throws NotFoundHttpException если отсутствует регион/подразделение
52      */
53     public function actionView($id)
54     {
55         return $this->render('view', [
56             'model' => $this->findModel($id),
57         ]);
58     }
59
60     /**
61      * Создание нового региона/подразделения.
62      * В случае успешного создания региона/подразделения, происходит переход к списку всех регионов/подразделений.
63      * @return mixed
64      */
65     public function actionCreate()
66     {
67         $model = new Regions();
68
69         if ($model->load(Yii::$app->request->post()) && $model->save()) {
70             return $this->redirect(['index', 'id' => $model->id]);
71         }
72
73         return $this->render('create', [
74             'model' => $model,
75         ]);
76     }
77
78     /**
79      * Изменение существующего региона/подразделения.
80      * В случае успешного редактирования, происходит переход к списку всех ергионов/подразделений.
81      * @param integer $id
82      * @return mixed
83      * @throws NotFoundHttpException если отсутствует регион/подразделение
84      */
85     public function actionUpdate($id)
86     {
87         $model = $this->findModel($id);
88
89         if ($model->load(Yii::$app->request->post()) && $model->save()) {
90             return $this->redirect(['index', 'id' => $model->id]);
91         }
92
93         return $this->render('update', [
94             'model' => $model,
95         ]);
96     }
97
98     /**
99      * Удаление существующего региона/подразделения.
100      * В случае успешного удаления, происходит переход к списку всех регоинов/подразделений.
101      * @param integer $id
102      * @return mixed
103      * @throws NotFoundHttpException если отсутсвует регион/подразделение
104      */
105     public function actionDelete($id)
106     {
107         $this->findModel($id)->delete();
108
109         return $this->redirect(['index']);
110     }
111
112     /**
113      * Finds the Regions model based on its primary key value.
114      * If the model is not found, a 404 HTTP exception will be thrown.
115      * @param integer $id
116      * @return Regions the loaded model
117      * @throws NotFoundHttpException if the model cannot be found
118      */
119     protected function findModel($id)
120     {
121         if (($model = Regions::findOne($id)) !== null) {
122             return $model;
123         }
124
125         throw new NotFoundHttpException(Yii::t('regions', 'The requested page does not exist.'));
126     }
127 }