yii 创建 验证码
转载地址: http://blog.sina.com.cn/s/blog_664c9f650100wkmp.html
1,在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',
),
);
2、(1)在LoginForm model rules()下添加:
//captche class needed
array('verifyCode', 'captcha','allowEmpty'=>!CCaptcha::checkRequirements()),
(2)LoginForm model下添加属性:
public $verifyCode;
3、在ContactForm model rules()下添加:
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
4、在login view下添加:
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
<?php echo $form->error($model,'verifyCode'); ?>
</div>