Код: Выделить всё
public function actionCreate()
{
$model = new RoleForm;
$this->performAjaxValidation($model);
if ($model->load(Yii::$app->request->post())) {
...
}
return $this->render('create', ['model' => $model]);
}
protected function performAjaxValidation($model)
{
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
}
Код: Выделить всё
public function actionCreate()
{
$model = new RoleForm;
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
...
}
return $this->render('create', ['model' => $model]);
}
Спасибо. Версия 2.0.1