Home >PHP Framework >YII >yii verification code is always wrong
Problem:
When making a request, I found that I entered the correct verification code, but it was prompted that the verification code was wrong.
Code example:
// 如果这里用到了验证码,就会出问题 $model = new Test(); $model->validate(); $model->save();
(Recommended tutorial: yii framework)
Reason:
If Model is separately validated before saving. After the verification is completed, the verification code will be regenerated. Then when we save the Model, we will also perform validate verification. During verification, the verification code has been regenerated, so it will not match.
Solution:
// 这样是正确的 $model = new Test(); // 把需要验证的 attribute 放进去,排除验证码字段 $model->validate(array('test1','test2')); $model->save()
For more programming-related content, please pay attention to the Programming Introduction column on the php Chinese website!
The above is the detailed content of yii verification code is always wrong. For more information, please follow other related articles on the PHP Chinese website!