承接 herroffizier/yii2-attribute-index-validator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

herroffizier/yii2-attribute-index-validator

最新稳定版本:1.0.0

Composer 安装命令:

composer require herroffizier/yii2-attribute-index-validator

包简介

Yii2 validator that adds incremental index to attribute values to make them unique.

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage Code Climate

This validator solves value collisions for unique model attributes by adding incremental index to repeating values. E.g. title will become title-1 if item with title already exists.

Such behavior may be useful for tasks like generating URLs and so on.

Installation

Install validator with Composer:

composer require --prefer-dist "herroffizier/yii2-attribute-index-validator:@stable"

Usage

Add validator to your model's rules array before required and unique validators (if any).

use herroffizier\yii2aiv\AttributeIndexValidator;

...

public function rules()
{
    return [
        [['attribute'], AttributeIndexValidator::className()],
        [['attribute'], 'required'],
        [['attribute'], 'unique'],
    ];
}

Validator has a few options to customize its behavior.

  • separator sets separator between original value and index. Default separator is -.
  • startIndex defines start index. Default value is 1.
  • filter defines additional filter to be applied to query used to check attribute uniqueness. May be either a string, an array or an anonymous function. In case of string or array filter value will be passed to \yii\web\ActiveQueryInterface::andWhere() method. In case of anonymous function its signature must be function($query) and instance of \yii\web\ActiveQueryInterface will be passed to it. Default value is null.

统计信息

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

GitHub 信息

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

其他信息

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