2017 © Pedro PelĂĄez
 

yii-extension yii-br-pack

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

image

igorsantos07/yii-br-pack

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  • Monday, January 26, 2015
  • by igorsantos07
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Yii Brazilian Package

Yii 1.1 Extension that provides various helpers for Brazilian localization., (*1)

  • Validators:
    • CPF: Cadastro de Pessoa FĂ­sica (like a Security Social Number in USA)
    • CNPJ: Cadastro Nacional de Pessoa JurĂ­dica
    • landlines: beginning with 2 and 3
    • cellphones: 9 digits or 8 digits beginning with 7, 8 or 9
  • Fields:
    • CPF and CNPJ
    • Polymorphic credit card field - given the name it turns into a PAN, CVV or Expiry field
    • Phone - landline, mobile, both, or area code only
  • Formatter:
    • CPF
    • Phone with area code
    • Money (alias of NumberFormatter::formatCurrency() which defaults to BRL

Installation

The preferred way to install this extension is through Composer., (*2)

Latest Stable Version Total Downloads, (*3)

Either run this:, (*4)

php composer.phar require --prefer-dist igorsantos07/yii-br-pack:1.*

or add this to the "require" section of your composer.json file., (*5)

"igorsantos07/yii-br-pack": "1.*"

Usage

Add the rules as the following example:, (*6)

models/PersonForm.php, (*7)

class PersonForm extends CModel {

  public $name;

  public $cpf;
  public $cnpj;
  public $cellphone;
  public $landline;
  public $phone;
  public $areaCode;

  public $card_number;
  public $card_cvv;
  public $card_expiry;

  public function rules() {
    // Using short array notation but the class is PHP <5.4 compatible ;)
    return [
      // CPF validator
      ['cpf', 'BrPack\Validator\Cpf'],
      // CNPJ validator
      ['cnpj', 'BrPack\Validator\Cnpj'],
      // Cellphone-only validator, checking area code inside the field
      ['cellphone', 'BrPack\Validator\Phone', 'type' => PhoneValidator::TYPE_CELLPHONE],
      // Cellphone-only validator, not validating area code
      [
        'cellphone',
        'BrPack\Validator\Phone',
        'type'     => BrPack\Validator\Phone::TYPE_CELLPHONE,
        'areaCode' => false
      ],
      // Landline-only validator
      ['landline', 'BrPack\Validator\Phone', 'type' => BrPack\Validator\Phone::TYPE_LANDLINE],
      // Any phone validator - cellphone or landline
      ['phone', 'BrPack\Validator\Phone'],
      // Cellphone validator with external area code check
      [
        'cellphone',
        'BrPack\Validator\Phone',
        'type'              => BrPack\Validator\Phone::TYPE_CELLPHONE,
        'areaCodeAttribute' => 'areaCode'
      ],
    ];
  }
}

views/person/edit.php, (*8)

beginWidget('CActiveForm, ['id' => 'my-person-form']) ?>

    <?=$form->label($model, 'name')?>
    <?=$form->textField($model, 'name')?>
    <?=$form->error($model, 'name')?>
    <br/>

    Current document: <?=Yii::app()->format->cpf('12365487588')?> // 123.654.875-88
    <?=$form->label($model, 'cpf')?>
    <?php $this->widget('BrPack\Field\Cpf', ['model' => $model, 'attribute' => 'cpf']) ?>
    <?=$form->error($model, 'cpf')?>
    <br/>

    Current phone: <?=Yii::app()->format->phone('21996543354')?> // (21) 99654-3354
    <?=$form->label($model, 'cellphone')?>
    <?php $this->widget('BrPack\Field\Phone', ['model' => $model, 'attribute' => 'cellphone', 'type' => 'mobile']) ?>
    <?=$form->error($model, 'cpf')?>
    <br/>

    <?=$form->label($model, 'card_number')?>
    <?php $this->widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_number']) ?>
    <?php $this->widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_expiry']) ?>
    <?php $this->widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_cvv']) ?>
    <?=$form->error($model, 'card_number')?>
    <?=$form->error($model, 'card_expiry')?>
    <?=$form->error($model, 'card_cvv')?>

    Amount to be charged in your card: <?=Yii::app()->format->money(9.99)?> // R$9,99
    <br/>

    <?=CHtml::submitButton()?>
endWidget() ?>

The Versions

26/01 2015

dev-master

9999999-dev

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

26/01 2015

v1.2.1

1.2.1.0

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

16/09 2014

v1.2.0

1.2.0.0

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

18/07 2014

v1.1.0

1.1.0.0

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

11/07 2014

v1.0.0

1.0.0.0

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

10/07 2014

v1.0.0-rc2

1.0.0.0-RC2

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline

10/07 2014

v1.0.0-rc

1.0.0.0-RC

Provide validations and easy masked fields for brazilian localization on Yii 1.1.*

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

form validator model yii field brazil brasil phone cnpj cpf credit card br cellphone landline