herroffizier/yii2-translit-validator
Composer 安装命令:
composer require herroffizier/yii2-translit-validator
包简介
Yii2 validator that transliterates model attribute values.
README 文档
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.
统计信息
- 总下载量: 30.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-04-07