1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace graychen\yii2\basic\auth\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use graychen\yii2\basic\auth\models\App; |
7
|
|
|
use yii\data\ActiveDataProvider; |
8
|
|
|
use yii\web\Controller; |
9
|
|
|
use yii\web\NotFoundHttpException; |
10
|
|
|
use yii\filters\VerbFilter; |
11
|
|
|
use yii\filters\AccessControl; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* AppController implements the CRUD actions for App models. |
15
|
|
|
*/ |
16
|
|
|
class AppController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
|
|
public function behaviors() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'access' => [ |
25
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
26
|
|
|
'rules' => [ |
27
|
|
|
[ |
28
|
|
|
'allow' => true, |
29
|
|
|
'roles' => ['@'], |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
], |
33
|
|
|
'verbs' => [ |
34
|
|
|
'class' => VerbFilter::className(), |
|
|
|
|
35
|
|
|
'actions' => [ |
36
|
|
|
'delete' => ['POST'], |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Lists all App models. |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
|
|
public function actionIndex() |
47
|
|
|
{ |
48
|
|
|
$dataProvider = new ActiveDataProvider([ |
49
|
|
|
'query' => App::find(), |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
return $this->render('index', [ |
53
|
|
|
'dataProvider' => $dataProvider, |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Displays a single App models. |
59
|
|
|
* @param integer $id |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function actionView($id) |
63
|
|
|
{ |
64
|
|
|
return $this->render('view', [ |
65
|
|
|
'models' => $this->findModel($id), |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Creates a new App models. |
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 App(); |
77
|
|
|
|
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
|
|
|
'models' => $model, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Updates an existing App models. |
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
|
|
|
|
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
|
|
|
'models' => $model, |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Deletes an existing App models. |
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
|
|
|
|
116
|
|
|
return $this->redirect(['index']); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Finds the App models based on its primary key value. |
121
|
|
|
* If the models is not found, a 404 HTTP exception will be thrown. |
122
|
|
|
* @param integer $id |
123
|
|
|
* @return App the loaded models |
124
|
|
|
* @throws NotFoundHttpException if the models cannot be found |
125
|
|
|
*/ |
126
|
|
|
protected function findModel($id) |
127
|
|
|
{ |
128
|
|
|
if (($model = App::findOne($id)) !== null) { |
129
|
|
|
return $model; |
130
|
|
|
} else { |
131
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.