Skip to content

Instantly share code, notes, and snippets.

@tguruslan
Created January 19, 2024 08:52
Show Gist options
  • Save tguruslan/a0adecddaf1628cfc12a59ff2d860fa1 to your computer and use it in GitHub Desktop.
Save tguruslan/a0adecddaf1628cfc12a59ff2d860fa1 to your computer and use it in GitHub Desktop.
Показати помилку валідації моделі yii2
<?php
public function action(Create|Update)(){
// ...
// ajax
}else if($model->load($request->post()) && !$model->validate()) {
return ['title'=>'Помилка','content'=>json_encode($model->getErrors(),JSON_UNESCAPED_UNICODE),'footer'=> Html::button(Yii::t('app', 'Закрити'),['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"])];
}else{
// no ajax
}else if($model->load($request->post()) && !$model->validate()) {
die(json_encode($model->getErrors(),JSON_UNESCAPED_UNICODE));
}else{
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment