Yii MVC user registration and User Logon (6)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.