控制器代码


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

05-18 17:25