定制 herroffizier/yii2-translit-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

herroffizier/yii2-translit-validator

Composer 安装命令:

composer require herroffizier/yii2-translit-validator

包简介

Yii2 validator that transliterates model attribute values.

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage Code Climate

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 is true.
  • forUrl replaces all invalid characters with invalidReplacement value. Default is true.
  • invalidReplacement is a replacement for invalid characters. Used in conjunction with forUrl. Default is -.
  • invalidRegexp is a regular expression which matches all incorrect symbols for URL. Used in conjunction with forUrl. 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 with forUrl. Default is false which means that no characters will be trimmed.

统计信息

  • 总下载量: 30.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固