在 Yii2 中报错:Model not inserted due to validation error.
1、在 Yii2 中报错:Model not inserted due to validation error.。如图1
2、代码实现如下
$input->value = $context->processDraft($value, $form, $field);
Yii::info(
[
'input' => $input->toArray()
],
'SurveyFormContentController.actionDraftUpdate',
);
if (!$input->save()) {
$transaction->rollBack();
return [
'code' => 10003,
'message' => '更新报名信息失败',
];
}
[
'input' => [
'id' => '1826803808485990',
'survey_form_id' => '1826803808485966',
'content_id' => '1826803808485988',
'field_id' => '1826803808485987',
'value' => 444,
],
]
3、但是,!$input->save(false) 不报错。问题分析,value 的值是 444(整数),但规则要求 value 必须是字符串。需要将 value 转换为字符串。
$input->value = (string)$context->processDraft($value, $form, $field);

近期评论