long399/yii2-math-captcha
最新稳定版本:0.1.2
Composer 安装命令:
composer require long399/yii2-math-captcha
包简介
yii2 MathCaptchaAction
README 文档
README
MathCaptchaAction for Yii Framework 2.0
Installation
The preferred way to install this extension is through composer. Either run
composer require --prefer-dist long399/yii2-math-captcha
or add
"long399/yii2-math-captcha": "~0.1"
to the require section of your composer.json file.
Available operations
- Addition.
- Subtraction.
- Multiplication.
Default addition or subtraction operation will be used randomly.
Usage
controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \long399\captcha\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, ], ... ]; }
model:
class MyModel extends \yii\db\ActiveRecord { public $captcha; ... public function rules() { return [ ... ['captcha', 'captcha', 'captchaAction' => '/site/captcha'], ... ]; } ... }
view:
... echo $form->field($model, 'captcha')->widget(\yii\captcha\Captcha::class, [ 'captchaAction' => "/site/captcha", 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>', ]); ...
If you want to use only expressions with a subtraction operation e.g., then you need to set the operations property accordingly in the description of the action in the controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \app\components\actions\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, 'operations' => ['-'], ], ... ]; }
Expressions with multiplication
If you want to use also expressions with a multiplication operation, then you need to set the operations property accordingly in the description of the action in the controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \app\components\actions\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, 'operations' => ['+', '-', '*'], ], ... ]; }
Three kinds of expressions can be generated:
- Expression with multiplication.
- Expression with multiplication and addition.
- Expression with multiplication and subtraction.
Author
long399, e-mail: long399@mail.ru
统计信息
- 总下载量: 2.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-16