public function actionSelected()
{
if (Yii::$app->request->isPost) {
$ids = Yii::$app->request->post('items', []);
$saved = false;
$models = Users::findAll($ids);
foreach ($models as $key => $model) {
$model->validate();
if ($model->hasErrors()) {
$result = [];
foreach ($model->getErrors() as $attribute => $errors) {
$result[Html::getInputId($model, $attribute)] = $errors;
}
}
if ($model->save()) {
$saved = true;
}
}
if ($saved) {
Yii::$app->session->addFlash('success', 'Статусы были изменены');
} else {
return $this->asJson(['validation' => $result]);
}
}
return $this->redirect('index');
}