herroffizier / yii2-translit-validator
Yii2 validator that transliterates model attribute values.
Installs: 28 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Type:yii2-extension
pkg:composer/herroffizier/yii2-translit-validator
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: 2025-10-25 22:45:21 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.
sourceAttributeas mentioned above points to source attribute which value should be transliterated. Empty by default and required.lowercaseenforces lower case for transliterated string. Default istrue.forUrlreplaces all invalid characters withinvalidReplacementvalue. Default istrue.invalidReplacementis a replacement for invalid characters. Used in conjunction withforUrl. Default is-.invalidRegexpis a regular expression which matches all incorrect symbols for URL. Used in conjunction withforUrl. Default is/[^a-z0-9]+/iwhich matches all non-alphanumeric symbols.trimInvalidtrims invalid characters at beginning and at end of given string. Used in conjunction withforUrl. Default isfalsewhich means that no characters will be trimmed.