| Conditions | 4 |
| Paths | 6 |
| Total Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function asJsonModelErrors($model): Response |
||
| 19 | { |
||
| 20 | $models = is_array($model) ? $model : [$model]; |
||
| 21 | |||
| 22 | $response = Yii::$app->getResponse(); |
||
| 23 | $response->format = Response::FORMAT_JSON; |
||
| 24 | $response->statusCode = 422; |
||
| 25 | |||
| 26 | $result = []; |
||
| 27 | foreach ($models as $model) { |
||
| 28 | foreach ($model->getErrors() as $attribute => $errors) { |
||
| 29 | $result[Html::getInputId($model, $attribute)] = $errors; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | $response->data = $result; |
||
| 34 | return $response; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |