‘captcha‘ => [
‘class‘ => ‘yii\captcha\CaptchaAction‘,
// ‘backColor‘=>0x000000,//背景颜色
‘maxLength‘ => 4, //最大显示个数
‘minLength‘ => 4,//最少显示个数
‘padding‘ => 5,//间距
‘height‘=>45,//高度
‘width‘ => 75, //宽度
// ‘foreColor‘=>0xffffff, //字体颜色
‘offset‘=>4,
],
[‘verifyCode‘, ‘captcha‘,‘captchaAction‘=>‘user/captcha‘,‘on‘ => [‘login‘]]
= $form->field($model,‘verifyCode‘)->widget(
Captcha::className(),
[
‘template‘ => ‘{image}{input}‘,
‘captchaAction‘=>‘user/captcha‘, // 此注意要使用自己配置的那个控制器验证码路由
‘imageOptions‘=>[ ‘style‘=>‘cursor:pointer;width:77px‘]
]
)
imagecolordeallocate($image, $foreColor);
ob_clean(); // 此行为插入代码,目的是清空缓存区为输出图片提供干净空间。
ob_start();
imagepng($image);
imagedestroy($image);