PHPackages                             herroffizier/yii2-attribute-index-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. herroffizier/yii2-attribute-index-validator

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

herroffizier/yii2-attribute-index-validator
===========================================

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

1.0.0(10y ago)02.0kBSD-3-ClausePHP

Since Mar 29Pushed 10y ago1 watchersCompare

[ Source](https://github.com/herroffizier/yii2-attribute-index-validator)[ Packagist](https://packagist.org/packages/herroffizier/yii2-attribute-index-validator)[ RSS](/packages/herroffizier-yii2-attribute-index-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Yii2 Attribute Index Validator
==============================

[](#yii2-attribute-index-validator)

[![Build Status](https://camo.githubusercontent.com/7627cfc67a2d362ae53721d04e9585e232cc468a38aba8b4eaac1214bdf9012f/68747470733a2f2f7472617669732d63692e6f72672f686572726f6666697a6965722f796969322d6174747269627574652d696e6465782d76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/herroffizier/yii2-attribute-index-validator) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/e2bb27ff900ea9e40714802b3e1516e0c60c03aa3c80ae25090c2657778f49bb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686572726f6666697a6965722f796969322d6174747269627574652d696e6465782d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/herroffizier/yii2-attribute-index-validator/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/5fb5ea89026d93d8be396a1a4c04ed6d061297a7b2b9c5f5752d01b44ad0b4e8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686572726f6666697a6965722f796969322d6174747269627574652d696e6465782d76616c696461746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/herroffizier/yii2-attribute-index-validator/?branch=master) [![Code Climate](https://camo.githubusercontent.com/f92174605a9b5bb41cb60e9380f6b83489336be45f45619db8c33ae28de55f0d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f686572726f6666697a6965722f796969322d6174747269627574652d696e6465782d76616c696461746f722f6261646765732f6770612e737667)](https://codeclimate.com/github/herroffizier/yii2-attribute-index-validator)

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

[](#installation)

Install validator with Composer:

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

```

Usage
-----

[](#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`.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3697d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/820232d3f5de11b08332a98ca93b025ab46d7e3563ddaec2ce6d042828718983?d=identicon)[herroffizier](/maintainers/herroffizier)

---

Top Contributors

[![korotin](https://avatars.githubusercontent.com/u/277992?v=4)](https://github.com/korotin "korotin (8 commits)")

---

Tags

validatorindexyii2extensionyiiyii 2

###  Code Quality

TestsCodeception

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/herroffizier-yii2-attribute-index-validator/health.svg)

```
[![Health](https://phpackages.com/badges/herroffizier-yii2-attribute-index-validator/health.svg)](https://phpackages.com/packages/herroffizier-yii2-attribute-index-validator)
```

###  Alternatives

[kdn/yii2-domain-validator

Domain name validator for Yii 2.

11122.3k1](/packages/kdn-yii2-domain-validator)[nepstor/yii2-datetime-compare-validator

Yii2 validator for compare datetime.

1283.7k1](/packages/nepstor-yii2-datetime-compare-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
