6. Generate a verification code;
7. The controller accesses other classes in the form of methods;
Verification Code principle:
When drawing a picture, the verification code is stored in the session. The verification code information entered by the user is compared with the information stored in our session.
View section:
<Tr> <TD align = "right"> <? PHP echo $ form-> labelex ($ user_login, 'verifycode');?> </TD> <? PHP echo $ form-> textfield ($ user_login, 'verifycode', array ('SIZE' => 15, 'class' => 'inputbg ',);?> <! -- Display the verification code image/use a small object to display the verification code --> <? PHP $ this-> widget ('ccaptcha ');?> <? PHP echo $ form-> error ($ user_login, 'verifycode');?> </TD> </tr>
Model section (logon form model ):
Public $ verifycode; // Verification Code attribute public function attributelabels () {return array ('username' => 'username', 'Password' => 'password ', 'verifycode' => 'verification code ', 'memberme' => 'Remember logon status',);} public function rules () {return array (// username and password are requiredarray ('username', 'required', 'message' => 'username mandatory '), array ('Password ', 'requestred', 'message' => 'password required '), // rememberme needs to be a booleanarray ('memberme', 'boolean '), // password needs to be authenticated // array ('Password', 'authenticate'), // verify the authenticity of the user name and password, use a custom method to verify the Array ('Password', 'authenticate'), // verify the verification code array ('verifycode', 'captcha ', 'message' => 'Enter the correct Verification Code '),);}
Where can I check the rules? Search for lanxiang from Shandong technical school!
Controller part:
/** Verification code generation * the following code indicates that in the current controller, access other classes in the form of Methods * We access./index. php? R = user/CAPTCHA will access the ccaptchaaction in the method. At this time, the verification code is generated * The run () in the ccaptchaaction class will be used () method * the controller is not responsible for displaying images. ** who will use the user/CAPTCHA route? * A: The view form is called indirectly ($ this-> widget ('ccaptcha ')) */function actions () {return array ('captcha '=> array ('class' => 'System. web. widgets. CAPTCHA. ccaptchaaction', 'width' => 75, // set the verification code width and height to 'height' => 30,). // we can define a class outside, you can access // user/CO in this way to access the computer. in PHP, the run () method 'co' => array ('class' => 'application. controllers. computer ',),);}
Analysis:
Contact between form and controller:
$ This-> widget ('ccaptcha '); indirectly calls the Controller's method to route user/CAPTCHA
Change verification code:
Yii MVC user registration and User Logon (6)