yii2验证码

action设置  放在CommonController中 继成yii\web\Controller


public function actions()
	{
		return  [
			'captcha' => [
				'class' => 'yii\captcha\CaptchaAction',
				'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
				'backColor'=>0x5090c1,//背景颜色
				'maxLength' => 4, //最大显示个数
				'minLength' => 4,//最少显示个数
				'padding' => 5,//间距
				'height'=>40,//高度
				'width' => 100,  //宽度
				'foreColor'=>0xffffff,     //字体颜色
				'offset'=>3,        //设置字符偏移量 有效果
				//'controller'=>'login',        //拥有这个动作的controller
			],
		];
	}

form

public $verifycode;
['verifycode', 'captcha', 'captchaAction'=>'/common/captcha'],


view

echo Captcha::widget(['name'=>'captchaimg','captchaAction'=>'/common/captcha','imageOptions'=>['id'=>'captchaimg', 'title'=>'换一个', 'alt'=>'换一个', 'style'=>'cursor:pointer;'],'template'=>'{image}']); 

解决页面刷新不刷新验证码
<script>
	<?php $this->beginBlock('js_end') ?>
	$(document).ready(function(){$("#captchaimg").click();});
	<?php $this->endBlock(); ?>
</script>
<?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_LOAD); ?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值