ProxyController::actionUpdate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use app\modules\admin\models\Proxy;
6
use app\modules\admin\models\ProxySearch;
7
use Yii;
8
use yii\filters\VerbFilter;
9
use yii\web\Controller;
10
use yii\web\NotFoundHttpException;
11
12
/**
13
 * ProxyController implements the CRUD actions for Proxy model.
14
 */
15
class ProxyController extends Controller
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function behaviors()
21
    {
22
        return [
23
            'verbs' => [
24
                'class' => VerbFilter::class,
25
                'actions' => [
26
                    'delete' => ['POST'],
27
                ],
28
            ],
29
        ];
30
    }
31
32
    /**
33
     * Lists all Proxy models.
34
     *
35
     * @return mixed
36
     */
37
    public function actionIndex()
38
    {
39
        $searchModel = new ProxySearch();
40
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
41
42
        return $this->render('index', [
43
            'searchModel' => $searchModel,
44
            'dataProvider' => $dataProvider,
45
        ]);
46
    }
47
48
49
    /**
50
     * Creates a new Proxy model.
51
     * If creation is successful, the browser will be redirected to the 'view' page.
52
     *
53
     * @return mixed
54
     */
55
    public function actionCreate()
56
    {
57
        $model = new Proxy();
58
        $model->loadDefaultValues();
59
60
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
61
            return $this->redirect(['proxy/index']);
62
        }
63
64
        return $this->render('create', [
65
            'model' => $model,
66
        ]);
67
    }
68
69
    /**
70
     * Updates an existing Proxy model.
71
     * If update is successful, the browser will be redirected to the 'view' page.
72
     *
73
     * @param integer $id
74
     * @return mixed
75
     * @throws NotFoundHttpException if the model cannot be found
76
     */
77
    public function actionUpdate($id)
78
    {
79
        $model = $this->findModel($id);
80
81
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
82
            return $this->redirect(['proxy/index']);
83
        }
84
85
        return $this->render('update', [
86
            'model' => $model,
87
        ]);
88
    }
89
90
    /**
91
     * Deletes an existing Proxy model.
92
     * If deletion is successful, the browser will be redirected to the 'index' page.
93
     *
94
     * @param integer $id
95
     * @return mixed
96
     * @throws \Throwable
97
     * @throws \yii\db\StaleObjectException
98
     * @throws \yii\web\NotFoundHttpException if the model cannot be found
99
     */
100
    public function actionDelete($id)
101
    {
102
        $this->findModel($id)->delete();
103
104
        return $this->redirect(['index']);
105
    }
106
107
    /**
108
     * Finds the Proxy model based on its primary key value.
109
     * If the model is not found, a 404 HTTP exception will be thrown.
110
     *
111
     * @param integer $id
112
     * @return Proxy the loaded model
113
     * @throws NotFoundHttpException if the model cannot be found
114
     */
115
    protected function findModel($id)
116
    {
117
        if (($model = Proxy::findOne($id)) !== null) {
118
            return $model;
119
        }
120
121
        throw new NotFoundHttpException('The requested page does not exist.');
122
    }
123
}
124