本文以实例形式讲述了yii创建验证码的方法,具体步骤如下所示:
一、在SiteController action()下添加如下代码:
array(
'class'=>'CCaptchaAction','backColor'=>0xFFFFFF,),// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.PHP?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',);
二、(1)在LoginForm model rules()下添加代码:
!CCaptcha::checkRequirements()),
PHP;">
public $verifyCode;
三、在ContactForm model rules()下添加代码:
PHP;">
// verifyCode needs to be entered correctly
array('verifyCode',
PHP;">
labelEx($model,'verifyCode');
?>
widget('CCaptcha');
?>
textField($model,'verifyCode');
?>
error($model,'verifyCode');
?>