model
属性
public $verifyCode;
规则
public function rules() { return [ // verifyCode needs to be entered correctly ['verifyCode', 'captcha'], ]; }
public function attributeLabels() { return [ 'verifyCode' => 'Verification Code', ]; }
controller
public function actions() { return ['captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; }视图
use yii\captcha\Captcha;<!-- 验证码--> <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 'template' => '<div class="row"><div class="col-lg-10">{input}</div><br><div class="col-lg-3">{image}</div></div>', ]) ?>