herroffizier / yii2-translit-validator
Yii2 validator that transliterates model attribute values.
Installs: 25 865
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Type:yii2-extension
Requires
- jbroadway/urlify: 1.0.*@dev
- yiisoft/yii2: *
Requires (Dev)
- codeception/codeception: 2.0.*
- codeception/specify: *
- codeception/verify: *
- phing/phing: *
- squizlabs/php_codesniffer: dev-master
- yiisoft/yii2-codeception: *
This package is not auto-updated.
Last update: 2024-12-21 17:48:40 UTC
README
This validator takes value from one attribute and puts transliterated value to another attribute. Also, validator may prepare transliterated string for usage in URL. Transliteration is made by URLify.
Installation
Install validator with Composer:
composer require --prefer-dist "herroffizier/yii2-translit-validator:@stable"
Usage
Add validator to your model's rules array before required
validator (if any) and set its sourceAttribute
property to
point source attribute which value should be transliterated.
use herroffizier\yii2tv\TranslitValidator; ... public function rules() { return [ [['attribute'], 'required'], [ ['attribute_translit'], TranslitValidator::className(), 'sourceAttribute' => 'attribute' ], [['attribute_translit'], 'required'], ]; }
Validator has a few options to customize its behavior.
sourceAttribute
as mentioned above points to source attribute which value should be transliterated. Empty by default and required.lowercase
enforces lower case for transliterated string. Default istrue
.forUrl
replaces all invalid characters withinvalidReplacement
value. Default istrue
.invalidReplacement
is a replacement for invalid characters. Used in conjunction withforUrl
. Default is-
.invalidRegexp
is a regular expression which matches all incorrect symbols for URL. Used in conjunction withforUrl
. Default is/[^a-z0-9]+/i
which matches all non-alphanumeric symbols.trimInvalid
trims invalid characters at beginning and at end of given string. Used in conjunction withforUrl
. Default isfalse
which means that no characters will be trimmed.