integready/yii2-simplemath-captcha

简单数学验证码

1.0.3 2017-03-05 14:11 UTC

This package is auto-updated.

Last update: 2024-08-29 04:18:25 UTC


README

安装

安装此扩展的首选方式是通过 Composer.

运行以下命令之一:

php composer.phar require --prefer-dist integready/yii2-simplemath-captcha "dev-master"

或者将以下内容添加到你的 composer.json 文件的 require 部分:

"integready/yii2-simplemath-captcha": "dev-master"

用法

一旦安装了扩展,只需修改你的控制器,添加或更改 actions() 方法。

public function actions()
{
	return [
            ...
            'captcha' => [
                'class' => 'integready\simplemathcaptcha\CaptchaAction',
                'operators' => ['+','-','*'],
                'maxValue' => 10,
                'fontSize' => 18,
            ],
	];
}

在视图

<?=
$form->field($model, 'verifyCode')->widget(Captcha::className(), [
    'template' => '<div class="row"><div class="col-lg-2">{image}</div><div class="col-lg-10">{input}</div></div>',
])->hint('Hint: click on the equation to refresh')
?>

在 config/web.php

'rules' => [
    'site/captcha/<refresh:\d+>' => 'site/captcha',
    'site/captcha/<v:\w+>' => 'site/captcha',
]

screenshot