1.在所需要验证码的页面加入actions
public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', // 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 'height' => 50, 'width' => 80, 'minLength' => 4, 'maxLength' => 4, 'testLimit'=>900, ], ]; } |
2.页面中使用
$form->field($model,'CAPTCHA',['enableAjaxValidation'=>true,'enableClientValidation' => false,])->widget(Captcha::className() ,['captchaAction'=>'signup/captcha', 'options' => ['class' => 'form-control'], 'template'=>'<p style="float:left">{input}</p> {image} ','imageOptions'=>['alt'=>Yii::t('app','点击换图'),'title'=>Yii::t('app','点击换图'), 'style'=>'cursor:pointer']]) |
注意:
点击换图这里的模板是可以修改的