Yii2验证码使用教程

控制器代码


public function actions()
    {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
                'maxLength' => 4, //最大显示个数
                'minLength' => 4,//最少显示个数
                'height' => 42,//高度
                'width' => 120,  //宽度
                'offset' => 10, //设置字符偏移量 有效果
                'foreColor' => 0x000000,
            ]
        ];
    }

模型代码
在rules方法中添加如下一行


['captcha', 'captcha','captchaAction'=>'/rbac/user/captcha'],

注意captchaAction这个属性指向我们上面在控制中定义的captcha这个action。

原文地址:https://segmentfault.com/a/1190000016175213

猜你喜欢

转载自www.cnblogs.com/lalalagq/p/9973676.html