这期内容当中小编将会给大家带来有关使用yii怎么实现一个验证码功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
一、在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/pages' // They can be accessed via: index.php?r=site/page&view=FileName 'page'=>array( 'class'=>'CViewAction', ), );
二、(1)在LoginForm model rules()下添加代码:
//captche class needed array('verifyCode', 'captcha','allowEmpty'=>!CCaptcha::checkRequirements()),
(2)LoginForm model下添加属性:
public $verifyCode;
三、在ContactForm model rules()下添加代码:
// verifyCode needs to be entered correctly array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
四、在login view下添加代码:
labelEx($model,'verifyCode'); ?> widget('CCaptcha'); ?> textField($model,'verifyCode'); ?> error($model,'verifyCode'); ?>
上述就是小编为大家分享的使用yii怎么实现一个验证码功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。