This article describes the implementation of the yii verification code, which is just a small example of the application by the Author. it is also available on the internet. to sum up, I hope to help Yii enthusiasts who need it. 1. I use user logon, so add the following in sitecontroller:
This article describes the implementation of the yii verification code, which is just a small example of the application by the Author. it is also available on the internet. to sum up, I hope to help Yii enthusiasts who need it. 1. The author uses user logon, so add the following code in sitecontroller:
?
123456789101112 |
Publicfunctionactions () {returnarray (// captcha action renders the CAPTCHA image displayed on the contact page 'captcha '=> array ('class' => 'ccaptchaaction ', 'backcolor' => 0 xFFFFFF, // background color 'minlength' => 4, // The shortest is 4 bits 'maxlength' => 4, // The length is 4-bit 'Transparent' => true, // it is displayed as transparent. when this option is disabled, the background color is displayed ),); |
2. add the following code to the form File (view file such as login. php ):
?
1234567891011 |
LabelEx ($ model, 'verifycode');?> Widget ('ccaptcha ');?> TextField ($ model, 'verifycode');?> Enter verification code Error ($ model, 'verifycode');?> |
3. add the following code to the Loginform model (LoginForm. php) to add attribute fields. Otherwise, an error is returned (non-existent attribute)
?
12345 |
Public $ username; public $ password; public $ verifyCode; public $ rememberMe; private $ _ identity; |
We can see the verification code through the above operation, but during the operation, we will find that the verification code is still acceptable without being entered, because we have not specified that the verification is required, in the LoginForm. in php, add array ('verifycode', 'required') to specify the required parameters. if the verification code is missing, it will be shown in: