errors" method; 2. Check whether the return value of the overridden AR life cycle method is incorrect, with statements such as "yii\db\ActiveRecord::afterValidate()" ."/> errors" method; 2. Check whether the return value of the overridden AR life cycle method is incorrect, with statements such as "yii\db\ActiveRecord::afterValidate()" .">

Home  >  Article  >  PHP Framework  >  What to do if yii2 save fails?

What to do if yii2 save fails?

藏色散人
藏色散人Original
2020-07-20 09:17:243572browse

yii2 Solution to unsuccessful save: 1. Use the "$model->errors" method; 2. Check whether the return value of the overridden AR life cycle method is incorrect, with statements such as "yii\db\ ActiveRecord::afterValidate()".

What to do if yii2 save fails?

Possible reasons for yii2 save failure

1. No field rules were added in the rules method

2.Transaction

3.Scenario

Solution

1.$model->errors<br>

2. Check whether the return value of the overridden AR life cycle method is incorrect

yii\db\ActiveRecord::beforeValidate():
yii\db\ActiveRecord::afterValidate()
yii\db\ActiveRecord::beforeSave()
yii\db\ActiveRecord::afterSave()

Recommended: "yii Tutorial"


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

Statement:
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