Home > PHP Framework > YII > body text

What should I do if yii2 fails to save update data?

藏色散人
Release: 2020-07-22 11:36:53
Original
3270 people have browsed it

yii2 The solution to the failure of saving updated data: first find and open the original script file that caused the error; then add validation rules for the new field in Rules in the model class, or set the field to "safe".

What should I do if yii2 fails to save update data?

YII2 failed to update data

Cause:

CLI mode, scheduled task. Synchronize DB data in other systems through views.

Recommended: "yii Tutorial"

Process:

The original script has been written, and it has been modified based on the existing ones and added new fields. .

After adding the field, it was executed, but it was always unsuccessful. The utime recorded in the table could also be updated successfully, but only the newly added field failed to be updated.

Try to print the $model->validate() result with no problem. $model->save() also returns true. $model->errors() returns empty. All is fine.

Suddenly remembered that the newly added fields were not added in the model class, so I changed it to $model->save(false) to turn off verification. Still unsuccessful.

Solution:

Add validation rules for new fields to Rules in the model class, or set the field to safe.

Summary:

What a cheat. Save(false) used to be OK, but this time it doesn’t work. .

The analysis should be a syntax problem. This time the data assignment method is

$info->attributes = $data;

The above is the detailed content of What should I do if yii2 fails to save update data?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!