1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\backend\tests\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\data\ActiveDataProvider; |
7
|
|
|
use yii\web\Controller; |
8
|
|
|
use yii\web\NotFoundHttpException; |
9
|
|
|
use yii\filters\VerbFilter; |
10
|
|
|
use yii\filters\AccessControl; |
11
|
|
|
use zacksleo\yii2\backend\tests\models\User; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* UserController implements the CRUD actions for User model. |
15
|
|
|
*/ |
16
|
|
|
class UserController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Lists all User models. |
20
|
|
|
* @return ActiveDataProvider |
21
|
|
|
*/ |
22
|
|
|
public function actionIndex() |
23
|
|
|
{ |
24
|
|
|
$params = Yii::$app->request->bodyParams; |
25
|
|
|
$userSearch = new \mdm\admin\models\searchs\User(); |
26
|
|
|
return $userSearch->search($params); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Displays a single User model. |
31
|
|
|
* @param integer $id |
32
|
|
|
* @return mixed |
33
|
|
|
*/ |
34
|
|
|
public function actionView($id) |
35
|
|
|
{ |
36
|
|
|
return $this->findModel($id); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Creates a new User model. |
41
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
42
|
|
|
* @return User |
43
|
|
|
*/ |
44
|
|
|
public function actionCreate() |
45
|
|
|
{ |
46
|
|
|
$model = new User(); |
47
|
|
|
$model->load(Yii::$app->request->bodyParams) && $model->save(); |
48
|
|
|
return $model; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Updates an existing User model. |
53
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
54
|
|
|
* @param integer $id |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function actionUpdate($id) |
58
|
|
|
{ |
59
|
|
|
$model = $this->findModel($id); |
60
|
|
|
return $model->load(Yii::$app->request->post()) && $model->save(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Deletes an existing User model. |
65
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
66
|
|
|
* @param integer $id |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
public function actionDelete($id) |
70
|
|
|
{ |
71
|
|
|
return $this->findModel($id)->delete(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Finds the User model based on its primary key value. |
76
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
77
|
|
|
* @param integer $id |
78
|
|
|
* @return User the loaded model |
79
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
80
|
|
|
*/ |
81
|
|
|
protected function findModel($id) |
82
|
|
|
{ |
83
|
|
|
if (($model = User::findOne($id)) !== null) { |
|
|
|
|
84
|
|
|
return $model; |
85
|
|
|
} else { |
86
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|