2017 © Pedro Peláez
 

yii2-extension yii2-attribute-index-validator

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

image

herroffizier/yii2-attribute-index-validator

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

  • Tuesday, March 29, 2016
  • by herroffizier
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,234 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Yii2 Attribute Index Validator

Build Status Scrutinizer Code Quality Code Coverage Code Climate, (*1)

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., (*2)

Such behavior may be useful for tasks like generating URLs and so on., (*3)

Installation

Install validator with Composer:, (*4)

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)., (*5)

use herroffizier\yii2aiv\AttributeIndexValidator;

...

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

Validator has a few options to customize its behavior., (*6)

  • 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.

The Versions

29/03 2016

dev-develop

dev-develop

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

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 validator yii yii 2 index

29/03 2016

dev-master

9999999-dev

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

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 validator yii yii 2 index

29/03 2016

1.0.0

1.0.0.0

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

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 validator yii yii 2 index