byonchev/zf2-kickbox

提供通过 http://kickbox.io 进行电子邮件验证的 Zend Framework 2 模块

dev-master 2016-06-08 09:02 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:14:53 UTC


README

ZF2Kickbox 是一个模块,提供了使用 http://kickbox.io 进行电子邮件验证的 Zend Framework 2 验证器

安装

  1. "byonchev/zf2-kickbox": "dev-master" 添加到您的 composer.json 中,并运行 php composer.phar update
  2. ZF2Kickbox 添加到您的 application.config.php
<?php
return [
    'modules' => [
        ...
        'ZF2Kickbox'
    ]
    ...
];

使用方法

首先,您需要从 https://kickbox.io/app/api/settings 获取一个 API 密钥(如果尚未创建账户)

  1. 编程方式
<?php

use Zend\Form\Form;
use Zend\Form\Element;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
use ZF2Kickbox\Validator\Kickbox;

class RegistrationForm extends Form
{
    public function __construct($name = null, $options = [])
    {
        parent::__construct($name, $options);
        
        $this->add(new Element('email'));
        
        $inputFilter      = new InputFilter();
        $input            = new Input('email');
        
        $kickboxValidator = new Kickbox(['apiKey' => 'xxxxxxxxxxxxxxxxx']);
        
        $input->getValidatorChain()->attach($kickboxValidator);

        $inputFilter->add($input);
        $this->setInputFilter($inputFilter);
    }
}