Home > PHP Framework > YII > body text

yii verification code is always wrong

王林
Release: 2020-02-18 11:46:03
Original
1968 people have browsed it

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();
Copy after login

(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()
Copy after login

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!

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 [email protected]
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!