In this paper, we describe the method of Yii to create a verification code in the form of an example, as follows:
First, add the following code under Sitecontroller action ():
return Array (//CAPTCHA action renders the CAPTCHA image displayed on the contact page ' captcha ' =>array (' class ' = = ') Ccaptchaaction ', ' BackColor ' =>0xffffff,),//page action renders "static" pages stored under ' Protected/views/site/pa Ges '//They can be accessed via:index.php?r=site/page&view=filename ' page ' =>array (' class ' = ' cviewaction ',) ,);
Second, (1) Add the code under LoginForm Model Rules ():
Captche class Neededarray (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),
(2) Add properties under LoginForm Model:
Public $verifyCode;
Third, add the code under Contactform Model Rules ():
Verifycode needs to be entered Correctlyarray (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),
Iv. Add the code under Login view:
<?phpecho $form->labelex ($model, ' verifycode ');? ><?php$this->widget (' Ccaptcha ');? ><?phpecho $form->textfield ($model, ' verifycode ');? ><?phpecho $form->error ($model, ' verifycode ');? >
This example code is only the main function of the brief, the reader can also be based on their own project requirements to further refine the program code, so that its function more practical.