1
|
|
|
<?php |
2
|
|
|
namespace zacksleo\yii2\romrelease\controllers; |
3
|
|
|
|
4
|
|
|
use Yii; |
5
|
|
|
use zacksleo\yii2\romrelease\models\RomRelease; |
6
|
|
|
use yii\data\ActiveDataProvider; |
7
|
|
|
use yii\filters\AccessControl; |
8
|
|
|
use yii\web\Controller; |
9
|
|
|
use yii\web\NotFoundHttpException; |
10
|
|
|
use yii\filters\VerbFilter; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* RomReleaseController implements the CRUD actions for RomRelease model. |
14
|
|
|
*/ |
15
|
|
|
class DefaultController extends Controller |
16
|
|
|
{ |
17
|
|
|
public $enableCsrfValidation = false; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @inheritdoc |
21
|
|
|
*/ |
22
|
|
|
public function behaviors() |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
'access' => [ |
26
|
|
|
'class' => AccessControl::className(), |
27
|
|
|
'rules' => [ |
28
|
|
|
[ |
29
|
|
|
'allow' => true, |
30
|
|
|
'roles' => ['@'], |
31
|
|
|
] |
32
|
|
|
] |
33
|
|
|
], |
34
|
|
|
'verbs' => [ |
35
|
|
|
'class' => VerbFilter::className(), |
36
|
|
|
'actions' => [ |
37
|
|
|
'delete' => ['POST'], |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Lists all RomRelease models. |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
public function actionIndex() |
48
|
|
|
{ |
49
|
|
|
$dataProvider = new ActiveDataProvider([ |
50
|
|
|
'query' => RomRelease::find(), |
51
|
|
|
]); |
52
|
|
|
return $this->render('index', [ |
53
|
|
|
'dataProvider' => $dataProvider, |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Displays a single RomRelease model. |
59
|
|
|
* @param integer $id |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function actionView($id) |
63
|
|
|
{ |
64
|
|
|
return $this->render('view', [ |
65
|
|
|
'model' => $this->findModel($id), |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Creates a new RomRelease model. |
71
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
72
|
|
|
* @return mixed |
73
|
|
|
*/ |
74
|
|
|
public function actionCreate() |
75
|
|
|
{ |
76
|
|
|
$model = new RomRelease(); |
77
|
|
|
$model->setScenario('insert'); |
78
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
79
|
|
|
return $this->redirect(['view', 'id' => $model->id]); |
80
|
|
|
} else { |
81
|
|
|
return $this->render('create', [ |
82
|
|
|
'model' => $model, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Updates an existing RomRelease model. |
89
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
90
|
|
|
* @param integer $id |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function actionUpdate($id) |
94
|
|
|
{ |
95
|
|
|
$model = $this->findModel($id); |
96
|
|
|
$model->setScenario('update'); |
97
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
98
|
|
|
return $this->redirect(['view', 'id' => $model->id]); |
99
|
|
|
} else { |
100
|
|
|
return $this->render('update', [ |
101
|
|
|
'model' => $model, |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Deletes an existing RomRelease model. |
108
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
109
|
|
|
* @param integer $id |
110
|
|
|
* @return mixed |
111
|
|
|
*/ |
112
|
|
|
public function actionDelete($id) |
113
|
|
|
{ |
114
|
|
|
$this->findModel($id)->delete(); |
115
|
|
|
return $this->redirect(['index']); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Finds the RomRelease model based on its primary key value. |
120
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
121
|
|
|
* @param integer $id |
122
|
|
|
* @return RomRelease the loaded model |
123
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
124
|
|
|
*/ |
125
|
|
|
protected function findModel($id) |
126
|
|
|
{ |
127
|
|
|
if (($model = RomRelease::findOne($id)) !== null) { |
128
|
|
|
return $model; |
129
|
|
|
} else { |
130
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|