Skip to content

Helpers suitable for use with the Yii2 php framework

License

Notifications You must be signed in to change notification settings

spapad/yii2-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Helpers

Utilities for common tasks.

Validators

VatNumberValidator

VatNumberValidator validator validates if a string or integer can be a valid VAT number. This does not validate if a VAT number is registered for use.

Validaror Parameters

  • allowEmpty, boolean: Whether to allow empty value or not

Example rule

['afm', VatNumberValidator::className(), 'allowEmpty' => false],

DefaultOnOtherAttributeValidator

DefaultOnOtherAttributeValidator sets a default value otherAttributeValue on another attibute named otherAttribute, if that attribute does not have a value and if the value of the checked attribute is a certain one (if), or when replace is set to true.

Validaror Parameters

  • if, scalar: The value to check against the attribute value (not strict operator used)
  • otherAttributeValue, any value: The "default" value to set
  • otherAttribute, string: The name of the attribute to set (if empty)
  • replace, boolean: Set to true to force set otherAttribute

Example rule

[['do_action'], DefaultOnOtherAttributeValidator::className(), 'if' => 'yes', 'otherAttributeValue' => -1, 'otherAttribute' => 'selected_action_element'],

This is also covered by core Yii functionality

[ 
    'otherAttribute', 'filter', 
    'filter' => function ($value) {
        return $otherAttributeValue;
    },
    'when' => function($model) {
        return $model->attribute == $if;
    }
],

About

Helpers suitable for use with the Yii2 php framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages