@@ 43-63 (lines=21) @@ | ||
40 | * @param mixed $id ID of the model to be updated. |
|
41 | * @return mixed response |
|
42 | */ |
|
43 | public function run($id) |
|
44 | { |
|
45 | $model = $this->getModel($id); |
|
46 | $model->setScenario($this->scenario); |
|
47 | if ($model->load(Yii::$app->getRequest()->post())) { |
|
48 | if (Yii::$app->getRequest()->isAjax) { |
|
49 | Yii::$app->getResponse()->format = Response::FORMAT_JSON; |
|
50 | return ActiveForm::validate($model); |
|
51 | } |
|
52 | if ($model->save()) { |
|
53 | $this->addSuccessFlash(); |
|
54 | return $this->redirect($model); |
|
55 | } else { |
|
56 | $this->addErrorFlash(); |
|
57 | } |
|
58 | } |
|
59 | ||
60 | return $this->controller->render($this->view, [ |
|
61 | $this->nameVariableModel => $model, |
|
62 | ]); |
|
63 | } |
|
64 | } |
|
65 |
@@ 77-97 (lines=21) @@ | ||
74 | * Creates new record. |
|
75 | * @return mixed response |
|
76 | */ |
|
77 | public function run() |
|
78 | { |
|
79 | $model = $this->newModel(); |
|
80 | $model->setScenario($this->scenario); |
|
81 | if ($model->load(\Yii::$app->getRequest()->post())) { |
|
82 | if (\Yii::$app->getRequest()->isAjax) { |
|
83 | \Yii::$app->getResponse()->format = Response::FORMAT_JSON; |
|
84 | return ActiveForm::validate($model); |
|
85 | } |
|
86 | if ($model->save()) { |
|
87 | $this->addSuccessFlash(); |
|
88 | return $this->redirect($model); |
|
89 | } else { |
|
90 | $this->addErrorFlash(); |
|
91 | } |
|
92 | } |
|
93 | ||
94 | return $this->controller->render($this->view, [ |
|
95 | $this->nameVariableModel => $model, |
|
96 | ]); |
|
97 | } |
|
98 | } |
|
99 |