| Conditions | 4 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function run() |
||
| 30 | { |
||
| 31 | /* @var $model \yii\db\ActiveRecord */ |
||
| 32 | $model = new $this->modelClass([ |
||
| 33 | 'scenario' => $this->scenario, |
||
| 34 | ]); |
||
| 35 | |||
| 36 | $model->load(Yii::$app->getRequest()->getBodyParams(), ''); |
||
| 37 | |||
| 38 | if ($this->checkAccess) { |
||
| 39 | call_user_func($this->checkAccess, $this->id, $model); |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($model->save()) { |
||
| 43 | $response = Yii::$app->getResponse(); |
||
| 44 | $response->setStatusCode(201); |
||
| 45 | $id = implode(',', array_values($model->getPrimaryKey(true))); |
||
| 46 | $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true)); |
||
| 47 | } elseif (!$model->hasErrors()) { |
||
| 48 | throw new ServerErrorHttpException('Failed to create the object for unknown reason.'); |
||
| 49 | } |
||
| 50 | |||
| 51 | return $model; |
||
| 52 | } |
||
| 54 |