brussens/yii2-recaptcha
最新稳定版本:1.1.0
Composer 安装命令:
composer require brussens/yii2-recaptcha
包简介
Google ReCaptcha v2.0 Yii 2.x.x extension
关键字:
README 文档
README
The main difference from the similar extensions is that this one doesn't require an application component with constant name, such as
\Yii::$app->recaptchaor something.
Install
Either run
php composer.phar require --prefer-dist brussens/yii2-recaptcha "*"
or add
"brussens/yii2-recaptcha": "*"
to the require section of your composer.json file.
Add to your bootstrap file:
$container->setSingleton(\ReCaptcha\ReCaptcha::class, function($container, $params, $config) { return new \ReCaptcha\ReCaptcha('your secret'); }); $container->set(\brussens\yii2\extensions\recaptcha\Widget::class, function($container, $params, $config) { return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config); });
Since Yii 2.0.11 you can also configure the container in the 'container' section of the app configuration:
'container' => [ 'definitions' => [ \brussens\yii2\extensions\recaptcha\Widget::class => function($container, $params, $config) { return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config); } ], 'singletons' => [ \ReCaptcha\ReCaptcha::class => function($container, $params, $config) { return new \ReCaptcha\ReCaptcha('your secret'); } ] ]
Add in your model validation rules
public function rules() { return [ ... ['verifyCode', \brussens\yii2\extensions\recaptcha\Validator::className()], ... ]; }
Add in your view
echo $form->field($model, 'verifyCode')->widget(\brussens\yii2\extensions\recaptcha\Widget::className());
If you use Pjax or multiple widgets on page
echo $form->field($model, 'verifyCode')->widget( \brussens\yii2\extensions\recaptcha\Widget::className(), [ 'options' => [ 'id' => 'insert-unique-widget-id' ] ]);
统计信息
- 总下载量: 24.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-27