OSDN Git Service

Слияние с develop
[invent/invent.git] / controllers / TypesController.php
1 <?php
2
3 namespace app\controllers;
4
5 use Yii;
6 use app\models\Types;
7 use app\models\TypesSearch;
8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter;
11
12 /**
13  * TypesController implements the CRUD actions for Types model.
14  */
15 class TypesController 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      * Lists all Types models.
34      * @return mixed
35      */
36     public function actionIndex()
37     {
38         $searchModel = new TypesSearch();
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      * Displays a single Types model.
49      * @param integer $id
50      * @return mixed
51      * @throws NotFoundHttpException if the model cannot be found
52      */
53     public function actionView($id)
54     {
55         return $this->render('view', [
56             'model' => $this->findModel($id),
57         ]);
58     }
59
60     /**
61      * Creates a new Types model.
62      * If creation is successful, the browser will be redirected to the 'view' page.
63      * @return mixed
64      */
65     public function actionCreate()
66     {
67         $model = new Types();
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      * Updates an existing Types model.
80      * If update is successful, the browser will be redirected to the 'view' page.
81      * @param integer $id
82      * @return mixed
83      * @throws NotFoundHttpException if the model cannot be found
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      * Deletes an existing Types model.
100      * If deletion is successful, the browser will be redirected to the 'index' page.
101      * @param integer $id
102      * @return mixed
103      * @throws NotFoundHttpException if the model cannot be found
104      */
105     public function actionDelete($id)
106     {
107         $this->findModel($id)->delete();
108
109         return $this->redirect(['index']);
110     }
111
112     /**
113      * Finds the Types 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 Types the loaded model
117      * @throws NotFoundHttpException if the model cannot be found
118      */
119     protected function findModel($id)
120     {
121         if (($model = Types::findOne($id)) !== null) {
122             return $model;
123         }
124
125         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
126     }
127 }