/**
  * Performs AJAX validation.
  * @param array|Model $models
  * @throws \yii\base\ExitException
  */
 protected function performAjaxValidation($models)
 {
     if (\Yii::$app->request->isAjax) {
         if (is_array($models)) {
             $result = [];
             foreach ($models as $model) {
                 if ($model->load(\Yii::$app->request->post())) {
                     \Yii::$app->response->format = Response::FORMAT_JSON;
                     $result = array_merge($result, ActiveForm::validate($model));
                 }
             }
             echo json_encode($result);
             \Yii::$app->end();
         } else {
             if ($models->load(\Yii::$app->request->post())) {
                 \Yii::$app->response->format = Response::FORMAT_JSON;
                 echo json_encode(ActiveForm::validate($models));
                 \Yii::$app->end();
             }
         }
     }
 }
 /**
  * Performs ajax validation.
  * @param Model $model
  * @throws \yii\base\ExitException
  */
 protected function performAjaxValidation(Model $model)
 {
     if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         echo json_encode(ActiveForm::validate($model));
         \Yii::$app->end();
     }
 }