amnah/

yii-recaptcha

Yii - Recaptcha小部件和验证器

dev-master 2013-10-01 03:11 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:25:47 UTC


README

Yii Recaptcha扩展。此简单扩展旨在通过自定义主题使开发者能够完全控制他们的recaptcha样式。

请参阅 https://developers.google.com/recaptcha/docs/customization

安装

使用方法

  • 确保您有一个具有适当的"recaptcha"属性的模型
  • 添加路径别名(根据需要修改路径)
Yii::setPathOfAlias('YiiRecaptcha',Yii::getPathOfAlias("application.vendor.amnah.yii-recaptcha"));
  • 在视图文件中调用小部件(注意style属性,因为它决定了它调用的功能)
<?php $this->widget('YiiRecaptcha\Recaptcha', array(
    'model' => $model,
    'attribute' => 'recaptcha',
    'publicKey' => '<recaptcha public key>',
    'style' => 'custom',
)); ?>
/**
 * The styling of the recaptcha widget, which will decide which function to use
 * For example,
 * $style = "default"   =>     $this->runDefault();
 * $style = "custom"    =>     $this->runCustom();
 * @var string
 */
  • 将验证器添加到模型的rules()中
public function rules() {
	return array(
		...
		array('recaptcha', 'required'),
        array('recaptcha', 'YiiRecaptcha\RecaptchaValidator', 'privateKey' => '<recaptcha private key>'),
		...
	);
}

扩展

  • 创建一个扩展YiiRecaptcha\Recaptcha或YiiRecaptcha\RecaptchaValidator类的新文件
  • 引用新文件而不是原始文件
<?php $this->widget('application.extensions.MyRecaptcha', array(...)); ?>