<?php 1.首先,在要实用验证码的控制器(Controller)中添加下面的代码 public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; } 2.在对应的model中添加rules规则 public $verifyCode; public function rules() { return [ [['username', 'pwd'], 'required'], [['username', 'pwd'], 'string', 'max' => 255], ['verifyCode','captcha'] ----添加验证码规则 ]; } 3.视图 <?php $form = ActiveForm::begin(); ?> ... <?= $form->field($model,'verifyCode')->widget(yii\captcha\Captcha::className())?> ... <?php ActiveForm::end(); ?>
yii 验证码
最新推荐文章于 2021-12-15 11:06:12 发布